user609926
user609926

Reputation: 831

How do i use the same template for multiple recipients?

I followed the "recipe" on the docusign dev center for sending a document from a pdf template i've uploaded. It works, but it's a workflow where each recipient can add onto (and/or sign) the same document.

I need to be able to generate documents form the same template for a list of recipients and have them all sign it. I'm thining the best way to do it would be to programmatically generate templates for each recipient, fill in their name and address info using a dataset I pull in through code and then send it off to each recipient to sign. This is the sample code I treid with:

            string username = conf.ConfigurationManager.AppSettings["username"];
        string password = conf.ConfigurationManager.AppSettings["password"];
        string integratorKey = conf.ConfigurationManager.AppSettings["integratorKey"]; 

        // initialize client for desired environment (for production change to www)
        ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
        Configuration.Default.ApiClient = apiClient;

string username = conf.ConfigurationManager.AppSettings["username"];
        string password = conf.ConfigurationManager.AppSettings["password"];
        string integratorKey = conf.ConfigurationManager.AppSettings["integratorKey"]; 

        // initialize client for desired environment (for production change to www)
        ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
        Configuration.Default.ApiClient = apiClient;

        // configure 'X-DocuSign-Authentication' header
        string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
        Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

        // we will retrieve this from the login API call
        string accountId = null;

        /////////////////////////////////////////////////////////////////
        // STEP 1: LOGIN API        
        /////////////////////////////////////////////////////////////////

        // login call is available in the authentication api 
        AuthenticationApi authApi = new AuthenticationApi();
        LoginInformation loginInfo = authApi.Login();

        // parse the first account ID that is returned (user might belong to multiple accounts)
        accountId = loginInfo.LoginAccounts[0].AccountId;
        var baseUrl = loginInfo.LoginAccounts[0].BaseUrl;
        // Update ApiClient with the new base url from login call
        apiClient = new ApiClient(loginInfo.LoginAccounts[0].BaseUrl);

        EnvelopeDefinition envDef = new EnvelopeDefinition();
        envDef.EmailSubject = "[TEMPLATE NAME]";

        // provide a valid template ID from a template in your account
        envDef.TemplateId = "[TEMPLATE ID]";
var rolesList = new List<TemplateRole>();

        // assign recipient to template role by setting name, email, and role name.  Note that the
        // template role name must match the placeholder role name saved in your account template.  
        TemplateRole tRole = new TemplateRole();
        tRole.Email = "XXX";
        tRole.Name = "XXX";
        tRole.RoleName = "Test Role";
        rolesList.Add(tRole);
            envDef.TemplateRoles = rolesList;
        envDef.Status = "sent";
        EnvelopesApi envelopesApi = new EnvelopesApi();
        EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);

Initially I tried just reinstatiating the TemplateRole ("trole" here), assiging new email addessses for each one and then using the envelope definition to send each one, but that was still sending each recipient the same shared document.

So do I have to create a template for each recipient if I want them to have their own signable document or is there a more practical way of doing this that I'm not seeing?

Upvotes: 0

Views: 431

Answers (1)

Majid Mallis
Majid Mallis

Reputation: 114

I'm a bit confused here but here is my 2 cents:

A template is basically a pre-set envelope with specific documents, recipient roles, tabs, and other business logic. The idea is to reuse the same "template" to generate as many envelopes.

A very simple use-case might be an NDA form for contributors to my open-source project: I set up a template from the NDA PDF document, upload the document to DocuSign, add placeholder tabs for several contributor information (name, email, date and signature), as well as placeholder for a recipient role (that I can call contributor). Once I save my template, I can copy the template ID from my DocuSign account and use it in the SDK as you mentioned, inside a loop:

  myRecipients.forEach(function(myRecipient) {
    var rolesList = new List<TemplateRole>();
    TemplateRole tRole = new TemplateRole();
    tRole.Email = myRecipient.email;
    tRole.Name = myRecipient.name;
    tRole.RoleName = "Test Role";
    rolesList.Add(tRole);
    envDef.TemplateRoles = rolesList;
    EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
    ...
  });

Upvotes: 1

Related Questions