Skip to navigation

How to create an envelope for offline signing (from a template)

View as Markdown

This topic demonstrates how to create an envelope from a template for offline signing.

Required data

Running the code in this how-to requires this data:

Data elementDescription
{ROLE_NAME}A string value for the role name associated with the template recipient. This value can be defined upon template creation. This value must exactly match (case-sensitive) the value shown in the Role field assigned to the recipient in the template.
{SIGNER_EMAIL}A string value for the email address where the signer will receive a notification of the signing request.
{SIGNER_NAME}A string value for the full name of the signer.
{TAB_LABEL}A string value identifying a text-based tab to override in the template. This value can be defined upon template creation using the Data Label field. This value must exactly match (case-sensitive) the value shown in the tab’s Data Label field in the template.
{TAB_VALUE}A string value to assign to the text tab in the template.
{TEMPLATE_ID}A GUID value that identifies a Docusign template that is used to create a Docusign envelope. This value is automatically generated by Docusign when the template is created.

Step 1. Log in to Docusign

To make the API call shown in this how-to, you must be logged in to Docusign.

See How to log in to Docusign from your app for details.

Step 2. Cache template

Use the method shown to cache the template you wish to use to construct your envelope.

DSTemplateDelegate templateDelegate = DocuSign.getInstance().getTemplateDelegate();
templateDelegate.cacheTemplate("{TEMPLATE_ID}", new DSCacheTemplateListener() {
@Override
public void onStart() {
Log.d("cacheTemplate","cacheTemplate started");
}
@Override
public void onComplete(DSTemplate template) {
Log.d("cacheTemplate","cacheTemplate completed for template ID: " + template.getTemplateId());
}
@Override
public void onError(DSTemplateException exception) {
Log.e("cacheTemplate", exception.getLocalizedMessage());
}
});

Step 3. Create envelope defaults

When creating an envelope definition with a template, the documents, tabs, and most of the other envelope data will be automatically populated by your chosen template. To create an envelope from a template, you must:

  • Specify the ID of the template.
  • Specify the names, emails, and role names for each role in the template.
  • Provide a custom string to be assigned as the value of any tab objects identified by {TAB_LABEL} that you wish to override.

Note: Only text-based tabs are supported for tab defaults.

ArrayList<DSRecipientDefault> recipientDefaults = new ArrayList<DSRecipientDefault>();
String emailBlurb = "Please sign";
String envelopeTitle = "Investment Agreement";
DSRecipientDefault recipient1 = new DSRecipientDefault(
"{SIGNER_NAME}",
"{SIGNER_EMAIL}",
1L, //RecipientID
"{ROLE_NAME}",
DSEnvelopeDefaultsUniqueRecipientSelectorType.ROLE_NAME
);
recipientDefaults.add(recipient1);
HashMap<String, String> tabValueDefaults = new HashMap<String, String>(){{
put("{TAB_LABEL}","{TAB_VALUE}");
}};
DSEnvelopeDefaults envelopeDefaults = new DSEnvelopeDefaults(
recipientDefaults,
null,
emailBlurb,
envelopeTitle,
tabValueDefaults,
null
);

Step 4. Create the envelope

Next, use the envelope defaults you created in the previous step to create an envelope.

templateDelegate.useTemplateOffline(context,
"{TEMPLATE_ID}",
envelopeDefaults,
new DSOfflineUseTemplateListener() {
@Override
public void onCancel(String templateId, String envelopeId) {
Log.d("useTemplateOffline", "Signing canceled for envelope ID: " + envelopeId + " from template ID: " + templateId);
}
@Override
public void onComplete(String envelopeId) {
Log.d("useTemplateOffline", "Signing completed for envelope ID: " + envelopeId);
}
@Override
public void onError(DSTemplateException exception) {
Log.e("useTemplateOffline", exception.getLocalizedMessage());
}
}
);

Expected response

If the account used for authentication is set as the signer for the envelope, you will see the Android SDK’s native offline signing screen, and be prompted to complete the offline signing process.

Native signing screen, Android SDK

Once signing has been completed, or if the envelope has a remote signer, the envelope will be cached directly for sync later.

Next steps