对于以下要求我们想使用DocuSce for SalesForce:
1.内部用户,单击页面布局上触发DocuSign的按钮
2.社区用户,单击VF页面上的按钮以触发DocuSign
为此,我已连接salesforce和Docusign帐户。并完成了基本配置,例如在DocuSign和SalesForce之间挂钩自定义变量,使用pdf创建模板以及一些标签,如签名,初始和日期签名。假设模板ID为aa3d9632-1595-4fef-87dd-1795334edf9d
。
现在,对于上面的第一个要求,我在页面布局上创建了一个JavaScript按钮,它使用创建的模板aa3d9632-1595-4fef-87dd-1795334edf9d
。在此处,当内部用户点击按钮时,收件人可以看到模板中包含的所有标签(签名,初始和日期签名)。
对于第二个要求,我使用SOAP API来触发DocuSign。由于我已经有了aa3d9632-1595-4fef-87dd-1795334edf9d
模板,我也想在第二个要求中使用相同的模板。为此,我在下面的代码中使用CreateEnvelopeFromTemplates()
方法:
//Step #1) Buiding Template, Recipient and Envelope information
// 1.1) Put the created template from DocuSign
DocuSignAPI.TemplateReference templetRef = new DocuSignAPI.TemplateReference();
templetRef.Template = aa3d9632-1595-4fef-87dd-1795334edf9d;
templetRef.TemplateLocation = 'Server';
DocuSignAPI.ArrayOfTemplateReference templetRefs = new DocuSignAPI.ArrayOfTemplateReference();
templetRefs.TemplateReference = new DocuSignAPI.TemplateReference[]{templetRef};
system.debug('templetRefs: '+templetRefs);
// 1.2) Create a Recipient
DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
recipient.Email = docuSign_email;
recipient.UserName = docuSign_fName+' '+docuSign_lName;
recipient.Type_x = 'Signer';
recipient.ID = 1;
recipient.RoutingOrder = 1;
recipient.RequireIDLookup = false;
DocuSignAPI.ArrayOfRecipient1 recipients = new DocuSignAPI.ArrayOfRecipient1();
recipients.Recipient = new DocuSignAPI.Recipient[]{recipient};
system.debug('recipients: '+recipients);
// 1.3) Construct the envelope information
DocuSignAPI.EnvelopeInformation envelopeInfo = new DocuSignAPI.EnvelopeInformation();
envelopeInfo.Subject = 'Terms of Agreement for your Signature';
envelopeInfo.EmailBlurb = 'We are sending you this request for your electronic signature, please review and electronically sign by following the link above. ';
envelopeInfo.AccountId = accountId;
//Populate Application as a Custom Field in Envelope
DocuSignAPI.CustomField custFiled = new DocuSignAPI.CustomField();
custFiled.Name = 'DSFSSourceObjectId';
custFiled.Value = docuSign_appID;
custFiled.show = 'False';
custFiled.Required = 'True';
custFiled.CustomFieldType = 'Text';
DocuSignAPI.ArrayOfCustomField CustFields = new DocuSignAPI.ArrayOfCustomField();
//CustFields.CustomField = new DocuSignAPI.CustomField[]{custFiled,accFiled};
CustFields.CustomField = new DocuSignAPI.CustomField[]{custFiled};
envelopeInfo.CustomFields = CustFields;
system.debug('envelopeInfo: '+envelopeInfo);
// Step #2) Create a Envelope with informtion created from step #1 and SendEnvelope
System.debug('Calling the API');
//DocuSignAPI.EnvelopeStatus es = dsApiSend.CreateAndSendEnvelope(envelope);
DocuSignAPI.EnvelopeStatus envelopStatus = dsApiSend.CreateEnvelopeFromTemplates(templetRefs, recipients,envelopeInfo,true);
envelopeId = envelopStatus.EnvelopeID;
在这种情况下,收件人无法看到模板中包含的任何标签(签名,初始和日期签名)。< / p>
奇怪的是,当用户单击页面布局JavaScript按钮单击时,这些选项卡是可见的,但不是在VF页面按钮单击时。
答案 0 :(得分:0)
您必须将收件人映射到模板角色
以下是需要更新的代码段。
recipient.RoleName = 'Signer 1'
查看完整代码here
// 1.2) Create a Recipient
DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
recipient.Email = docuSign_email;
recipient.UserName = docuSign_fName+' '+docuSign_lName;
recipient.Type_x = 'Signer';
recipient.ID = 1;
recipient.RoutingOrder = 1;
recipient.RequireIDLookup = false;
recipient.RoleName = 'Signer 1';
DocuSignAPI.ArrayOfRecipient1 recipients = new DocuSignAPI.ArrayOfRecipient1();
recipients.Recipient = new DocuSignAPI.Recipient[]{recipient};
ArrayOfTemplateReferenceRoleAssignment tras = new ArrayOfTemplateReferenceRoleAssignment();
TemplateReferenceRoleAssignment assign = new TemplateReferenceRoleAssignment();
assign.setRoleName(recipient.getRoleName());
assign.setRecipientID(recipient.getID());
tras.getRoleAssignment().add(assign);
templetRef.setRoleAssignments(tras);