Recent Entries
Search Blog
Be our friend
Populate Dynamic Tabs in a Template
A recent question on the DocuSign forums asked how to populate pre-placed Tabs in a Template from the API. This is a pretty common use-case for anyone who has a Document they want to mock-up in the Console and has dynamic values that can be updated from the API.





// Includes
include_once 'include/session.php'; // initializes session and provides
include_once 'api/APIService.php';
include 'include/utils.php';
// Check to make sure we're logged in
loginCheck();
// Envelope variables [CHANGE THESE]
$Subject = 'Subject of the email';
$EmailBlurb = 'email text';
$templateID = 'TEMPLATE_ID_HERE';
// Recipient and Tab variables [CHANGE THESE]
$UserName = 'FULLNAME_HERE';
$Email = 'EMAIL_HERE';
$RoleName = 'Signer'; // The Role you defined in the Console
$TabLabel = 'TestField'; // TabLabel that you created
$TabValue = 'Awesome'; // Value that you want to use to pre-populate
// Create envelope information
$envinfo = new EnvelopeInformation();
$envinfo->Subject = $Subject;
$envinfo->EmailBlurb = $EmailBlurb;
$envinfo->AccountId = $_SESSION["AccountID"];
// Create 1 Recipient
$r = new Recipient();
$r->UserName = $UserName;
$r->Email = $Email;
$r->ID = '1';
$r->RoleName = $RoleName;
$r->Type = RecipientTypeCode::Signer;
$recipients = array($r);
// Create the ReferenceRoleAssignment for Recipient
$ra = new TemplateReferenceRoleAssignment();
$ra->RecipientID = $r->ID;
$ra->RoleName = $r->RoleName;
$roleAssignments = array($ra);
// Construct the template reference
$tref = new TemplateReference();
$tref->TemplateLocation = TemplateLocationCode::Server;
$tref->Template = $templateID;
$tref->RoleAssignments = $roleAssignments;
// Construct a TemplateReferenceFieldDataDataValue value
$fd = new TemplateReferenceFieldDataDataValue();
$fd->TabLabel = $TabLabel;
$fd->Value = $TabValue;
// Add array to TemplateReferenceFieldData->DataValues (per WSDL and APIService.php)
$fdd = new TemplateReferenceFieldData();
$fdd->DataValues = array($fd);
$tref->FieldData = $fdd;
$templateReferences = array($tref);
// Send the Envelope
$api = getAPI();
$csParams = new CreateEnvelopeFromTemplates();
$csParams->EnvelopeInformation = $envinfo;
$csParams->Recipients = $recipients;
$csParams->TemplateReferences = $templateReferences;
$csParams->ActivateEnvelope = true; // Email the Envelope
try {
$status = $api->CreateEnvelopeFromTemplates($csParams)->CreateEnvelopeFromTemplatesResult;
if ($status->Status == EnvelopeStatusCode::Sent) {
echo "Envelope Sent Successfully";
exit;
}
} catch (SoapFault $e) {
$_SESSION["errorMessage"] = array($e, $api->__getLastRequest(), $csParams);
header("Location: error.php");
}

DocuSign is hiring! If you're interested in engineering more ways for people to easily use the industry standard for electronic signatures, contact mikeb@docusign.com.

