19626
2023-07-17 254ea442ff0e0a7a97e9f481e9f127a782cba840
force-app/main/default/pages/ConsumApplyQR.page
@@ -13,18 +13,45 @@
            sforce.connection.sessionId = '{!GETSESSIONID()}';
            var record = sforce.connection.query("select id from Attachment where ParentId = \'{!Consum_Apply__c.Id}\' and name = \'QRCode-{!Consum_Apply__c.Name}\'");
            // var record = sforce.connection.query("select id from Attachment where ParentId = \'{!Consum_Apply__c.Id}\' and name = \'QRCode-{!Consum_Apply__c.Name}\'");
            var record = sforce.connection.query("select ContentDocumentId from ContentDocumentLink where LinkedEntityId = \'{!Consum_Apply__c.Id}\'");
            // 不存在qr文件时,新生成一个,并连到申请单上
            console.log(record.size);
            if(record.size > 0){
                var records = record.getArray("records");
                var idList = records.map(obj => "'" + obj.ContentDocumentId + "'").join(",");
                record = sforce.connection.query("select Id from ContentDocument where Id in (" + idList + ") and Title = \'QRCode-{!Consum_Apply__c.Name}\'");
                console.log("select Id from ContentDocument where Id in (" + idList + ") and Title = \'QRCode-{!Consum_Apply__c.Name}\'");
            }
            console.log(record.size);
            if (record.size == 0) {
                var atta = new sforce.SObject("Attachment");
                atta.Name = "QRCode-{!Consum_Apply__c.Name}";
                atta.ParentId = "{!Consum_Apply__c.Id}";
                atta.Body = src;
                var result = sforce.connection.create([atta]);
                // var atta = new sforce.SObject("Attachment");
                // atta.Name = "QRCode-{!Consum_Apply__c.Name}";
                // atta.ParentId = "{!Consum_Apply__c.Id}";
                // atta.Body = src;
                // var result = sforce.connection.create([atta]);
                var version = new sforce.SObject("ContentVersion");
                version.Title = "QRCode-{!Consum_Apply__c.Name}";
                version.VersionData = src;
                version.ContentLocation = "s";
                version.PathOnClient = "QRCode-{!Consum_Apply__c.Name}.jpg";
                var result = sforce.connection.create([version]);
                console.log(result[0].id);
                version = sforce.connection.query("select ContentDocumentId from ContentVersion where Id = \'" + result[0].id + "\'");
                console.log(version);
                version = version.getArray("records");
                console.log(version);
                var link = new sforce.SObject("ContentDocumentLink");
                link.LinkedEntityId = "{!Consum_Apply__c.Id}";
                link.ContentDocumentId = version[0].ContentDocumentId;
                link.ShareType = 'I';
                link.Visibility = 'AllUsers';
                result = sforce.connection.create([link]);
                var es = new sforce.SObject("Consum_Apply__c");
                es.Id = "{!Consum_Apply__c.Id}";
                es.QRId__c = result[0].id;
                es.QRId__c = version[0].ContentDocumentId;
                result = sforce.connection.update([es]);
            }
            else {