From bdb1a98b64a2cf59bcfd575c579aa0742e0de954 Mon Sep 17 00:00:00 2001
From: chenjingwu <chenjingwu@prec-tech.com>
Date: 星期五, 24 五月 2024 17:21:32 +0800
Subject: [PATCH] 1
---
force-app/main/default/pages/ConsumApplyBR.page | 54 ++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/force-app/main/default/pages/ConsumApplyBR.page b/force-app/main/default/pages/ConsumApplyBR.page
index 289ae20..40b049d 100644
--- a/force-app/main/default/pages/ConsumApplyBR.page
+++ b/force-app/main/default/pages/ConsumApplyBR.page
@@ -52,30 +52,56 @@
var srcNew = getImgBase64(src);
src = srcNew.substring(22, srcNew.length);
sforce.connection.sessionId = '{!GETSESSIONID()}';
+ console.log(src);
+ // var record = sforce.connection.query("select id from Attachment where ParentId = \'{!Consum_Apply__c.Id}\' and name = \'BRCode-{!Consum_Apply__c.Name_No__c}\'");
- var record = sforce.connection.query("select id from Attachment where ParentId = \'{!Consum_Apply__c.Id}\' and name = \'BRCode-{!Consum_Apply__c.Name_No__c}\'");
+ var record = sforce.connection.query("select Id,ContentDocumentId from ContentDocumentLink where LinkedEntityId = \'{!Consum_Apply__c.Id}\'");
+ 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 = \'BRCode-{!Consum_Apply__c.Name_No__c}\'");
+ }
// 鏃€伀銇傘倢銇扮劇瑕�
if (record.size == 0) {
- var atta = new sforce.SObject("Attachment");
- atta.Name = "BRCode-{!Consum_Apply__c.Name_No__c}";
- atta.ParentId = "{!Consum_Apply__c.Id}";
- atta.Body = src;
- var result = sforce.connection.create([atta]);
-
- var es = new sforce.SObject("Consum_Apply__c");
- es.Id = "{!Consum_Apply__c.Id}";
- es.BRId__c = result[0].id;
- result = sforce.connection.update([es]);
- //鐢宠涔︽洿鏂板け璐ョ殑璇濆啀娆℃洿鏂�
- } else if ("{!Consum_Apply__c.BRId__c}" == '' || "{!Consum_Apply__c.BRId__c}" == null) {
+ // var atta = new sforce.SObject("Attachment");
+ // atta.Name = "BRCode-{!Consum_Apply__c.Name_No__c}";
+ // atta.ParentId = "{!Consum_Apply__c.Id}";
+ // atta.Body = src;
+ // var result = sforce.connection.create([atta]);
+ var version = new sforce.SObject("ContentVersion");
+ version.VersionData = src;
+ version.Title = "BRCode-{!Consum_Apply__c.Name_No__c}";
+ version.ContentLocation = 's';
+ version.PathOnClient= "BRCode-{!Consum_Apply__c.Name_No__c}.jpg";
+ var versionResult = sforce.connection.create([version]);
+ record = sforce.connection.query("SELECT Id,ContentDocumentId FROM ContentVersion WHERE Id =\'" + versionResult[0].id + "\'");
var records = record.getArray("records");
+ var link = new sforce.SObject("ContentDocumentLink");
+ link.ContentDocumentId = records[0].ContentDocumentId;
+ link.LinkedEntityId = "{!Consum_Apply__c.Id}";
+ link.ShareType = 'I';
+ link.Visibility = 'AllUsers';
+ var result = sforce.connection.create([link]);
+
var es = new sforce.SObject("Consum_Apply__c");
es.Id = "{!Consum_Apply__c.Id}";
es.BRId__c = records[0].Id;
result = sforce.connection.update([es]);
+ //鐢宠涔︽洿鏂板け璐ョ殑璇濆啀娆℃洿鏂�
+ } else if ("{!Consum_Apply__c.BRId__c}" == '' || "{!Consum_Apply__c.BRId__c}" == null) {
+ var records = record.getArray("records");
+ var version = new sforce.SObject("ContentVersion");
+ version = sforce.connection.query("select Id,ContentDocumentId from ContentVersion where ContentDocumentId = \'" + records[0].Id + "\'");
+ version = version.getArray("records");
+ // 瀛樺湪qr鏃讹紝缁戝埌鐢宠鍗曚笂
+ var es = new sforce.SObject("Consum_Apply__c");
+ es.Id = "{!Consum_Apply__c.Id}";
+ es.BRId__c = version[0].Id;
+ result = sforce.connection.update([es]);
// TODO Name澶夈倧銈嬪彲鑳芥�с亗銈娿�乽psert銇仐銇俱仚
} else {
- alert(record[0].id);
+ var records = record.getArray("records");
+ // alert(records[0].Id);
}
}
// BRcode鐢熸垚寰屻�丄ttachment銈掍綔鎴�
--
Gitblit v1.9.1