1

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.

duckie715
  • 165
  • 3
  • 13
  • What do you mean when you say you're trying to "add the templates to our REST Header request"? What exactly are you trying to accomplish and which api call are you using? – Ergin Oct 08 '13 at 23:52
  • Envelope creation. Our create envelope page has form fields for what my earlier problem was and it displays the templates that are available to the logged in user with checkboxes next to them. The user selects the templates they want to put in the envelope (they go into an array), fills in the form fields and then they would send the envelope. I need to have them go out with the request. So instead of one hardcoded templateId, I need to send multiple templates. Does that make sense? – duckie715 Oct 09 '13 at 01:06

1 Answers1

2

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": "firstrecipient@gmail.com",
                "name": "John Doe",
                "recipientId": "1",
                "roleName": "RoleOne"
              }
            ]
          }
        }
      ]
    },
    {
      "serverTemplates": [
        {
          "sequence": "2",
          "templateId": "44D9E888-3D86-4186-8EE9-7071BC87A0DA"
        }
      ],
      "inlineTemplates": [
        {
          "sequence": "2",
          "recipients": {
            "signers": [
              {
                "email": "secondrecipient@gmail.com",
                "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.

Ergin
  • 9,254
  • 1
  • 19
  • 28