duckie715
duckie715

Reputation: 165

Adding Docusign Template array into REST Header

So I'm back again. My problem is this: I have an array of Docusign Templates from checkboxes in a Codeigniter view:

<?php
    echo form_open('create_envelope');
    foreach ($response["envelopeTemplates"] as $envelopeTemplate) { ?>
        <li><?php echo form_checkbox('templatearray[]', $envelopeTemplate["templateId"], FALSE), $envelopeTemplate["name"]; ?></li>
<?php } ?>

What I'm trying to do is add the templates to our REST Header request:

$data = array(
    "accountId" => $accountId,
    "emailSubject" => "Hello World!",
    "emailBlurb" => "This comes from PHP",
    "templateId" => "ID from template array here",
    "templateRoles" => array(
        array(
            "tabs" => array(
            "textTabs" => array (
                array (
                    "tabLabel" => "lic_num", 
                    "value" => "$license_number"
                ),
                array (
                    "tabLabel" => "ubi_num",
                    "value" => "$ubi_number"
                ),
                array (
                    "tabLabel" => "tra_nam",
                    "value" => "$trade_name"
                )
             )
          ),
          "email" => "$applicant_email",
          "name" => "$applicant_name",
          "roleName" => "Applicant"
          ) 
     ),
    "status" => "sent"
);

Is this possible?

EDIT: So I got it to work using loops to get my data in the request, but I'm running into an interesting problem. If I put one or two templates in the envelope, it sends fine. If I put more than two in, it duplicates the templates. Here is my code for the complicated loops:

$compTempArray = array();
$applicant_name = $this->input->post("applicant_name");
$applicant_email = $this->input->post("applicant_email");
$license_number = $this->input->post("license_number");
$ubi_number = $this->input->post("ubi_number");
$trade_name = $this->input->post("trade_name");
foreach($hello as $key => $value) {
    if(sizeof($hello) > 1) {
        for($i = 1; $i < sizeof($hello); $i++) {
            $compTempArray[] = array("serverTemplates" => array(
                array(
                    "sequence" => $i,
                    "templateId" => $value
                )
            ),
            "inlineTemplates" => array(
                array(
                    "sequence" => $i,
                    "recipients" => array(
                        "signers" => array(
                            array(
                                "tabs" => array(
                                            "textTabs" => array (
                                                            array ("tabLabel" => "lic_num", "value" => $license_number),
                                                            array ("tabLabel" => "ubi_num", "value" => $ubi_number),
                                                            array ("tabLabel" => "tra_nam", "value" => $trade_name)
                                            )
                                ),
                                "email" => "*********@*****.com",
                                "name" => $applicant_name,
                                "recipientId" => "1",
                                "roleName" => "Applicant"
                            ),
                        )
                    )
                )
            ));

        }
        $data = array("accountId" => $accountId,
                      "emailSubject" => "Hello World!",
                      "emailBlurb" => "This comes from PHP",
                      "compositeTemplates" => $compTempArray,
                      "status" => "sent");
        } else {
            $data = array("accountId" => $accountId,
                      "emailSubject" => "Hello World!",
                      "emailBlurb" => "This comes from PHP",
                      "templateId" => "$value",
                      "templateRoles" => array(
                                            array(
                                                "tabs" => array(
                                                            "textTabs" => array (
                                                                            array ("tabLabel" => "lic_num", "value" => $license_number),
                                                                            array ("tabLabel" => "ubi_num", "value" => $ubi_number),
                                                                            array ("tabLabel" => "tra_nam", "value" => $trade_name)
                                                            )
                                                ),
                                                "email" => "*********@*****.com",
                                                "name" => $applicant_name,
                                                "roleName" => "Applicant"

                                            )   
                                         ),
                    "status" => "sent"); 
        }
    }

Any idea why it would do this?

NEW EDIT: Update on this weirdness: one to two - one copy of each template, three - it doubles the amount of each template, four - it triples the amount, five - it quadruples the amount.

NEWEST EDIT: So as it turns out, it was the for loop that I was using to try and increment the sequence. I got rid of the loop and hardcoded the sequence to 1. That fixed it.

Upvotes: 1

Views: 223

Answers (1)

Ergin
Ergin

Reputation: 9356

To apply multiple templates to a single envelope you'll need to use the compositeTemplates structure.

compositeTemplates can get complex very quickly but they do allow for great flexibility and functionality for your envelopes. The API documentation is the best place to read about compositeTemplates but as previously mentioned the April 2012 Templates Webinar is also a good resource. The third example provides a basic use of compositeTemplates in that it shows you how to combine two server templates into one single envelope. You can use that as a base for your JSON.

To apply 2 server templates to a single envelope it uses the following JSON:

{
  "emailSubject": "DocuSign Templates Webinar - Example 3",
  "emailBlurb": "Example #3 - Composite Templates",
  "status": "sent",
  "compositeTemplates": [
    {
      "serverTemplates": [
        {
          "sequence": "1",
          "templateId": "55A80182-2E9F-435D-9B16-FD1E1C0F9D74"
        }
      ],
      "inlineTemplates": [
        {
          "sequence": "1",
          "recipients": {
            "signers": [
              {
                "email": "[email protected]",
                "name": "John Doe",
                "recipientId": "1",
                "roleName": "RoleOne"
              }
            ]
          }
        }
      ]
    },
    {
      "serverTemplates": [
        {
          "sequence": "2",
          "templateId": "44D9E888-3D86-4186-8EE9-7071BC87A0DA"
        }
      ],
      "inlineTemplates": [
        {
          "sequence": "2",
          "recipients": {
            "signers": [
              {
                "email": "[email protected]",
                "name": "Jane Doe",
                "recipientId": "1",
                "roleName": "RoleOne"
              }
            ]
          }
        }
      ]
    }
  ]
}

Note that the sequence value for each template determines the order of template application to the envelope. So in other words, the sequence value determines the document order, but since the templates might have matching/conflicting info (in terms of template roles for instance) the sequence value might also affect the end result of the envelope.

Upvotes: 2

Related Questions