When you send the documents for eSignature, you add custom DocuSign tags to the document. You can choose to set some initial values to the fields and also fetch the updated values if any from the fields in the template.

Use Case1

Suppose the agreement or proposal is sent to multiple recipients for signature, you can add tags to fields for each specific signer. For signer 1, add tags for Name and email and for signer 2 add tags for the name, email, and phone number.

Using the set Recipient Tabs API. you can set an initial value to a field in the generated document that is sent for signature. If the signer updates the field, you can fetch and update the field information to the account and other relevant objects in Salesforce using the get Recipient Tab APIs.

Use Case2

Suppose the agreement or proposal is to be sent to three recipients for signature, and you want to obtain the information from the signers. You can populate the fields such as Custom Tab1, Custom Tab2, and Custom Tab3 in your Salesforce org. You can add the custom tabs for the user to add their Name, Title, and Email.

You require a template that you want to send to your signers and you have to add tags to fields for each signer. 

After signer1 enters his Name and Title and signs the document, it is sent to signer 2. After signer 2 enters his Name and Title and signs the document, it is sent to signer 3. After signer 3 signs the document, it is sent back to the sender. The Name and Title are the custom tabs and are populated in the Salesforce once the batch job is run.

Perform the following steps to achieve this scenario.

1. Add Custom Fields to the DocuSign Recipients object.

2. Create the Custom Tags in DocuSign account.

3. Create the Template with the appropriate Custom Tags.

4. Add the classes under Apex Classes.

5. Ensure that DocuSign Custom Classes in System Properties has the callback class names populated with appropriate class names.

6. Ensure that Recipient Tabs Enabled check box in DocuSign System Properties is selected.

You can get a detailed description for all these steps in below sections.

To add custom fields

  1. Go to Setup > Build > Create > Objects and select DocuSign Recipients (Object Name: DocuSignDefaultRecipient2 , API Name: Apttus_DocuApi__DocuSignDefaultRecipient2__c ).
  2. Under the Custom Fields & Relationships related list, click New.
  3. Select Text radio button and click Next.
  4. Enter Field Label as Custom Tab1. Field Name is auto-populated.
  5. Enter the Length as 18.
  6. Click Next.
  7. Establish appropriate Field-Level Security.
  8. Click Next.
  9. Select appropriate page layouts to which you want to add this field.
  10. Click Save.

Adding Apex Classes

You can set information to the signer fields using set Tabs for each Recipient and getTabs for each recipient. These APIs enable you to set information in the document and also enable you to fetch the information set in these tags such as name, email, or company name. You can fetch the data the user enters in these fields and update records for an object such as Account, Contact, or Opportunity.

  • API to Get Custom Tabs
    If you want to update the information about the signer in records after the recipient signs and sends the agreement across, use the getCustomTabs APIs
  • API to Set Custom Tabs
    The setTabs API enables you to set initial values for certain fields in the Agreement. The value you set using the setTabs API is displayed on the envelope. Set the initial values using this API before you initiate the eSignature request.

To add apex class

  1. Go to Setup > Build > Develop > Apex Classes and click New.
  2. Paste the appropriate code.
  3. Click Save.

API to Get Custom Tabs

If you want to update the information about the signer in records after the recipient signs and sends the agreement across, use the getCustomTabs APIs. getTabs for each Recipient: Enables you to retrieve the values set within input tags for a field in the contract when the request for eSignature is completed.

We have customized the code as per Use Case 2. You can customize the code as per your business requirements.

The snippet below enables you to fetch and update the information of a signer:

/*
* Sample class for demonstrating how to get the values from DocuSign custom tags 
* and update the custom fields on DocuSign Default Recipient object on an Apttus Agreement
*/
global class DocuSignEnvelopeGetRecipientTabs2Imp implements Apttus_DocuApi.IDocuSignEnvelopeGetRecipientTabs2{
global DocuSignEnvelopeGetRecipientTabs2Imp(){

} 
global void getRecipientTabs(List<Apttus_DocuApi.GetRecipientTabsWrapper> iListGetRecipientTabsWrapper){


Set<ID> setParentId = new Set<ID>();
for(Apttus_DocuApi.GetRecipientTabsWrapper objGetRecipientTabsWrapper : iListGetRecipientTabsWrapper){
try{
ID parentId = ID.valueOf(objGetRecipientTabsWrapper.parentId);
if(!setParentId.contains(parentId)){
setParentId.add(parentId);
}
}catch(Exception ex){
System.debug('ERROR : it is DEMO...!');
}
}

List <Apttus_DocuApi__DocuSignDefaultRecipient2__c> listRecipients = [SELECT Apttus_CMDSign__AgreementId__c,Apttus_DocuApi__ReadOnlyEmail__c,Apttus_DocuApi__SigningOrder__c,CustomTab1__c,CustomTab2__c,CustomTab3__c from Apttus_DocuApi__DocuSignDefaultRecipient2__c where Apttus_CMDSign__AgreementId__c in :setParentId];
Map <String,Apttus_DocuApi__DocuSignDefaultRecipient2__c> recipientMap = new Map <String,Apttus_DocuApi__DocuSignDefaultRecipient2__c>();

for(Apttus_DocuApi__DocuSignDefaultRecipient2__c r : listRecipients){ 
String strKey = r.Apttus_CMDSign__AgreementId__c + String.valueOf(r.Apttus_DocuApi__SigningOrder__c);
recipientMap.put(strKey,r); 
} 
List<Apttus_DocuApi__DocuSignDefaultRecipient2__c> toUpdate = new List<Apttus_DocuApi__DocuSignDefaultRecipient2__c>();
for(Apttus_DocuApi.GetRecipientTabsWrapper objGetRecipientTabsWrapper : iListGetRecipientTabsWrapper){ 

try{

ID parentId = ID.valueOf(objGetRecipientTabsWrapper.parentId);

System.debug(System.LoggingLevel.ERROR, 'Parent Id == > '+parentId);
Apttus_DocuApi__DocuSignDefaultRecipient2__c docuSignDefaultRecipient = null;
System.debug(System.LoggingLevel.ERROR, 'Step 001 == >');

Apttus_DocuApi.DocuSignUtil2.DocuSignRecipientStatus objRecipeintStatus = objGetRecipientTabsWrapper.recipientStatus;
System.debug(System.LoggingLevel.ERROR, 'Step 001.1 == >');

String strKey = parentId + objRecipeintStatus.routingOrder;

Apttus_DocuApi.DocuSignUtil2.RecipientTabs rTabs = objRecipeintStatus.tabs;

//check if the recipient tab has text tabs

System.debug('Map values == > '+JSON.serialize(recipientMap));

if(recipientMap.containsKey(strKey)){
System.debug('Getting Map values for Id == > '+strKey);
docuSignDefaultRecipient = recipientMap.get(strKey);
}
if(rTabs.textTabs.size() > 0){
//populate the first custom field with the data in the first text tab
Apttus_DocuApi.DocuSignUtil2.textTab tTab = rTabs.textTabs[0];
docuSignDefaultRecipient.CustomTab1__c = String.ValueOf(tTab.value);

//populate the second custom field with the data in the second text tab
Apttus_DocuApi.DocuSignUtil2.textTab tTab1 = rTabs.textTabs[1];
docuSignDefaultRecipient.CustomTab2__c = String.ValueOf(tTab1.value); 
}

//check if the recipient tab has email tabs
if(rTabs.emailTabs.size() > 0){
//populate the third custom field with the data in the first email tab
Apttus_DocuApi.DocuSignUtil2.emailTab eTab = rTabs.emailTabs[0];
docuSignDefaultRecipient.CustomTab3__c = String.ValueOf(eTab.value);

}

toUpdate.add(docuSignDefaultRecipient);
} catch(Exception ex){
System.debug('ERROR AT the :'+ex.getMessage());
}
} // for

if(toUpdate.size() > 0){
update toUpdate;
System.debug('ERROR: UPDATE DocuSignDefaultRecipient: '+toUpdate.size()); 
} else{
System.debug('ERROR: UPDATE DocuSignDefaultRecipient: '+toUpdate.size());
}
}
}
CODE

API to Set Custom Tabs

The setTabs API enables you to set initial values for certain fields in the Agreement. The value you set using the setTabs API is displayed on the envelope. Set the initial values using this API before you initiate the eSignature request.

set Tabs for each Recipient: Provides an initial set of corresponding values for each tag type for a recipient when the request is sent to DocuSign. These are the initial values that are viewable and editable in the document you send to the signer for signature.

Before using the APIs ensure the following:

  • Ensure that the DocuSign Custom Classes with the field Add Recipient Tabs Callback Classispopulatedwith the callback class name, DocuSignEnvelopeSetRecipientTabs2Imp.
  • Ensure that you select theRecipientTabs Enabled checkbox under the DocuSign System Properties.
  • In the custom callback class, set the value and the anchor string for the custom tag, getRecipientTabsmethodiswherewe set the value and the anchor string for the custom tag that we want to prepopulate.

In the Custom Callback class, the getRecipientTabs method is where you set the value and the anchor string for the custom tag that you want to prepopulate. So, if you want to populate a text tab with some value, you should initialize the text tab in the getRecipientTabs method such as Apttus_DocuApi.DocuSignUtil.textTab objTextTab = new Apttus_DocuApi.DocuSignUtil.textTab(iRecipientId,'This Value','40','0','0'.The second parameter is the value that you need to set for the custom text tag, so for above example, the text tag has a value - 'This Value', when it shows up in DocuSign. You can set it to a dynamic value by pulling up any field through SOQL using the parentId. Then, while setting the anchor string for the tag, you can define what anchor string you are going to use in the template. Suppose you want to use \t {r}\anchortag, this is what you put in the custom class- objTextTab.anchorString = '\\t'+iRecipientId; objRecipientTabs.addTextTab(objTextTab). You then need to use the tag \t1\, \t2\ in the document that you are sending for signature, and you need to have the tag \t{r} \ defined under the DocuSign account under custom tags.

We have customized the code as per UseCase 2. You can customize the code below as per your business requirements.

The snippet below enables you to set default values for DocuSign tags.

/*
* Sample class for demonstarting how to set the default values for DocuSign tags 
*/
global class DocuSignEnvelopeSetRecipientTabs2Imp implements Apttus_DocuApi.IDocuSignEnvelopeSetRecipientTabs2{

global List<Apttus_DocuApi.SetRecipientTabsWrapper> listToSetRecipientTabsWrapper = new List<Apttus_DocuApi.SetRecipientTabsWrapper>();
global List<Apttus_DocuApi.SetRecipientTabsWrapper> setRecipientTabs(List<Apttus_DocuApi.SetRecipientTabsWrapper> iListSetRecipientTabsWrapper){
System.debug(System.LoggingLevel.ERROR, 'SETTER : Sep 001 ');
this.listToSetRecipientTabsWrapper = iListSetRecipientTabsWrapper;

for(Integer counter = 0 ; counter < listToSetRecipientTabsWrapper.size(); counter++){
Apttus_DocuApi.SetRecipientTabsWrapper objSetRecipientTabsWrapper = this.listToSetRecipientTabsWrapper.get(counter);
this.listToSetRecipientTabsWrapper[counter] = this.addRecipeintTabs(objSetRecipientTabsWrapper);
} 
System.debug(System.LoggingLevel.ERROR, 'SETTER : Sep 002 ');
return listToSetRecipientTabsWrapper; 
}

public Apttus_DocuApi.SetRecipientTabsWrapper addRecipeintTabs(Apttus_DocuApi.SetRecipientTabsWrapper iSetRecipientTabsWrapper){

System.debug(System.LoggingLevel.ERROR, 'SETTER : Sep 003 '); 
List<Apttus_DocuApi.DocuSignUtil.Recipient> listRecipient = iSetRecipientTabsWrapper.listRecipient;
String parentId = iSetRecipientTabsWrapper.parentId;

for(Integer counter = 0 ; counter < listRecipient.size(); counter++){ 

Apttus_DocuApi.DocuSignUtil.Recipient objRecipient = listRecipient.get(counter);

listRecipient[counter] = this.addRecipeintTab(objRecipient);
} 
System.debug(System.LoggingLevel.ERROR, 'SETTER : Sep 004 ');
iSetRecipientTabsWrapper.listRecipient = listRecipient;
return iSetRecipientTabsWrapper; 
}

public Apttus_DocuApi.DocuSignUtil.Recipient addRecipeintTab(Apttus_DocuApi.DocuSignUtil.Recipient iRecipient){
Apttus_DocuApi.DocuSignUtil.Recipient objRecipient = iRecipient;
System.debug(System.LoggingLevel.ERROR, 'SETTER : Sep 005 ');
objRecipient.tabs = getRecipientTabs(String.ValueOf(objRecipient.objectIndex+1));

return objRecipient;
}


public Apttus_DocuApi.DocuSignUtil.RecipientTabs getRecipientTabs(String iRecipientId){

System.debug(System.LoggingLevel.ERROR, 'SETTER : Sep 006 ');
Apttus_DocuApi.DocuSignUtil.RecipientTabs objRecipientTabs = new Apttus_DocuApi.DocuSignUtil.RecipientTabs();

//Set values for two text tags and one email tag in the document

Apttus_DocuApi.DocuSignUtil.emailTab objEmailTab = new Apttus_DocuApi.DocuSignUtil.emailTab(iRecipientId,'email'+iRecipientId+'@test.com','40','0','0');
Apttus_DocuApi.DocuSignUtil.textTab objTextTab = new Apttus_DocuApi.DocuSignUtil.textTab(iRecipientId,'text'+iRecipientId,'40','0','0');
Apttus_DocuApi.DocuSignUtil.textTab objTextTab1 = new Apttus_DocuApi.DocuSignUtil.textTab(iRecipientId,'title'+iRecipientId,'40','0','0');


objEmailTab.name = 'Email'+iRecipientId;
objEmailTab.tabLabel = 'Email'+iRecipientId;
objEmailTab.anchorString = '\\e'+iRecipientId+'\\';

objTextTab.name = 'Text'+iRecipientId;
objTextTab.tabLabel = 'Text'+iRecipientId;
objTextTab.anchorString = '\\tx'+iRecipientId+'\\';

objTextTab1.name = 'SecondText'+iRecipientId;
objTextTab1.tabLabel = 'SecondText'+iRecipientId;
objTextTab1.anchorString = '\\t'+iRecipientId+'\\';

objRecipientTabs.addEmailTab(objEmailTab);
objRecipientTabs.addTextTab(objTextTab);
objRecipientTabs.addTextTab(objTextTab1);

System.debug(System.LoggingLevel.ERROR, 'SETTER : Sep 007 ');
return objRecipientTabs;

}
}
CODE