Reputation: 21
For below requirements We wanted to use DocuSign for SalesForce:
1. Internal user, clicks a button on page layout which trigger DocuSign
2. Community user, clicks a button on VF page which triggers DocuSign
To do this, I have connected both salesforce and Docusign accounts. And done basic configuration like hooking up custom variables between DocuSign and SalesForce, creating template using pdf and some tabs like Signature, Initial and Date Signed. Let say template ID is aa3d9632-1595-4fef-87dd-1795334edf9d
.
Now, for 1st requirement from above, I have created a JavaScript button on page layout which is using created template aa3d9632-1595-4fef-87dd-1795334edf9d
. Here, when an internal user clicks on button, recipient can see all tabs (Signature, Initial and Date Signed) which were included in template.
For 2nd requirement, I am using SOAP API to trigger DocuSign. As I am already having a template aa3d9632-1595-4fef-87dd-1795334edf9d
, I wanted to use the same in my 2nd requirement as well. To do so, I am using CreateEnvelopeFromTemplates()
method please below piece of code:
//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;
In this case, recipient not able to see any tab (Signature, Initial and Date Signed) which were included in template.
Strangely these tabs are visible when user click on page layout JavaScript button click, but not on VF page button click.
Upvotes: 0
Views: 199
Reputation: 7393
You will have to map your recipient to your template role
Here is the code snippet that needs to be updated.
recipient.RoleName = 'Signer 1'
See complete code 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);
Upvotes: 0