Li Jun
2022-04-13 5c01ebbfddb6b8674430b47c22977bea2e350084
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0" encoding="UTF-8"?>
<WebLink xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>VOCSubmit</fullName>
    <availability>online</availability>
    <displayType>button</displayType>
    <linkType>javascript</linkType>
    <masterLabel>VOC提出</masterLabel>
    <openType>onClickJavaScript</openType>
    <protected>false</protected>
    <url>{!RequireScript(&quot;/soap/ajax/51.0/connection.js&quot;)}
{!RequireScript(&quot;/soap/ajax/51.0/apex.js&quot;)}
{!RequireScript(&quot;/resource/CommonUtilJs&quot;)} 
//2021-10-22 gwy 版本更改为51.0
var foo = function() {
    if (&quot;{!Report__c.Status__c}&quot; != &quot;草案中&quot;) {
        alert(&quot;不是草案中不能点击&quot;);
        return;
    }
 
    var rac = new sforce.SObject(&quot;Report__c&quot;);
    
    // share
    var resultSet = sforce.connection.query(&quot;SELECT Job_Category__c FROM User WHERE Id = &apos;{!Report__c.CreatedById}&apos;&quot;);
    var records = resultSet.getArray(&quot;records&quot;);
    var userAccess = new Array();
    if (records[0].Job_Category__c == &quot;销售服务&quot;) {
        userAccess.push(&apos;{!Report__c.JingliApprovalManagerId__c}_Read&apos;);
        userAccess.push(&apos;{!Report__c.BuchangApprovalManagerId__c}_Read&apos;);
        rac.VOC_CreatedBy_jingli__c = &apos;{!Report__c.JingliApprovalManagerId__c}&apos;;
        rac.VOC_CreatedBy_buzhang__c = &apos;{!Report__c.BuchangApprovalManagerId__c}&apos;;
    } else {
        userAccess.push(&apos;{!Report__c.SalesManagerId__c}_Read&apos;);
        userAccess.push(&apos;{!Report__c.BuchangApprovalManagerSalesId__c}_Read&apos;);
        rac.VOC_CreatedBy_jingli__c = &apos;{!Report__c.SalesManagerId__c}&apos;;
        rac.VOC_CreatedBy_buzhang__c = &apos;{!Report__c.BuchangApprovalManagerSalesId__c}&apos;;
    }
    userAccess.push(&apos;{!Report__c.ZongjianApprovalManagerId__c}_Read&apos;);
    var rtn = sforce.apex.execute(&apos;ControllerUtil&apos;,&apos;setSObjectShare&apos;,{sobjectName:&apos;Report__Share&apos;,rowCause:&apos;VOCShare__c&apos;,parentId:&apos;{!Report__c.Id}&apos;,userAccess:userAccess,ownerId:&apos;{!Report__c.OwnerId}&apos;});
    if (rtn != &apos;OK&apos;) {
        alert(rtn);
        return;
    }
 
    rac.Id = &quot;{!Report__c.Id}&quot;;
    rac.Status__c = &quot;填写完毕&quot;;
    var serverTimestamp = sforce.connection.getServerTimestamp();
    rac.Submit_time__c = serverTimestamp.timestamp;
    rac.Submit_report_day__c = serverTimestamp.timestamp;
    var result = sforce.connection.update([rac]);
 
    var messages = getConnectDMLErrorMessages(result);
    if (messages.length &gt; 0) {
        alert(messages.join(&quot;\n&quot;));
        return;
    }
    location.reload();
}
foo();</url>
</WebLink>