Skip to navigation

CreateEnvelopeFromTemplatesAndForms

View as Markdown

This method is used to create envelopes from a combination of a PDF form and a Docusign Template. Once all the data from the form is overlaid on the template the envelope is passed to the CreateAndSendEnvelope or CreateEnvelope method. Refer to CreateAndSendEnvelope method for the sending rules that are applied before the envelope can be sent.

This method has some similarities to the CreateEnvelopeFromTemplates method, in that both merge documents and templates, with the primary differences to the CreateEnvelopeFromTemplatesAndForms method being:

  • Docusign SecureFields (Tabs with TabType “Custom”) are extrapolated from the form itself. Instead of having to define the fields on a Template in advance, they can be derived from the form on the fly.
  • Templates, which are really just partially-defined Envelopes, can be stacked over each other, creating a Composite Template.
  • Templates do not need to be fully defined. For example, a template can be created to define only those items that cannot be derived from the form itself.

When a template is added or applied to an envelope and the template has a locked email subject and message (MessageLock is true), that subject and message is used for the envelope and cannot be changed even if another locked template is subsequently added or applied to the envelope. If an email subject or message is entered before adding or applying a locked template, the email subject and message will be overwritten with the email subject and message from the locked template.

// Configure the envelope information
DocuSignWeb.EnvelopeInformation envelopeInfo = new DocuSignWeb.EnvelopeInformation();
envelopeInfo.AccountId = _accountId;
envelopeInfo.EmailBlurb = "testing docusign creation services";
envelopeInfo.Subject = "create envelope from templates and forms test";
DocuSignWeb.CompositeTemplate template = new DocuSignWeb.CompositeTemplate();
DocuSignWeb.Recipient recipient1 = new DocuSignWeb.Recipient();
recipient1.UserName = "SignerOne";
// TODO: replace the email string with an actual email
recipient1.Email = "test email one";
recipient1.Type = DocuSignWeb.RecipientTypeCode.Signer;
recipient1.RequireIDLookup = false;
recipient1.RequireIDLookupSpecified = true;
recipient1.RoutingOrder = 1;
recipient1.RoutingOrderSpecified = true;
recipient1.RoleName = "One";
recipient1.ID = "1";
DocuSignWeb.Recipient recipient2 = new DocuSignWeb.Recipient();
recipient2.UserName = "Signer2";
// TODO: replace the email string with an actual email
recipient2.Email = "test email two";
recipient2.Type = DocuSignWeb.RecipientTypeCode.Signer;
recipient2.RequireIDLookup = false;
recipient2.RequireIDLookupSpecified = true;
recipient2.RoutingOrder = 2;
recipient2.RoutingOrderSpecified = true;
recipient2.RoleName = "Two";
recipient2.ID = "2";
DocuSignWeb.Recipient[] signers = { recipient1, recipient2 };
// Configure the inline templates
DocuSignWeb.InlineTemplate inlineTemplate = new DocuSignWeb.InlineTemplate();
inlineTemplate.Sequence = "1";
inlineTemplate.Envelope = new DocuSignWeb.Envelope();
inlineTemplate.Envelope.Recipients = signers;
inlineTemplate.Envelope.AccountId = _accountId;
// This tab matches the DateSigned tab assigned to recipient one
DocuSignWeb.Tab tab1 = new DocuSignWeb.Tab();
tab1.RecipientID = "1";
tab1.TabLabel = "DocuSignDateSignedOne";
tab1.Type = DocuSignWeb.TabTypeCode.DateSigned;
// This tab matches the SignHere tabs assigned to recipient two
DocuSignWeb.Tab tab2 = new DocuSignWeb.Tab();
tab2.RecipientID = "2";
tab2.TabLabel = "SignTwo\\*";
tab2.Type = DocuSignWeb.TabTypeCode.SignHere;
// This tab matches the SignHere tabs assigned to recipient one
DocuSignWeb.Tab tab3 = new DocuSignWeb.Tab();
tab3.RecipientID = "1";
tab3.TabLabel = "SignOne\\*";
tab3.Type = DocuSignWeb.TabTypeCode.SignHere;
// This tab matches the DateSigned tab assigned to recipient two
DocuSignWeb.Tab tab4 = new DocuSignWeb.Tab();
tab4.RecipientID = "2";
tab4.TabLabel = "DocuSignDateSignedTwo";
tab4.Type = DocuSignWeb.TabTypeCode.DateSigned;
// This tab matches nothing -- but that's okay!
// It will just get discarded
DocuSignWeb.Tab tab5 = new DocuSignWeb.Tab();
tab5.RecipientID = "1";
tab5.TabLabel = "asdf";
tab5.Type = DocuSignWeb.TabTypeCode.FullName;
inlineTemplate.Envelope.Tabs = new DocuSignWeb.Tab[] { tab1, tab2, tab3, tab4, tab5 };
template.InlineTemplates = new DocuSignWeb.InlineTemplate[] { inlineTemplate };
// Configure the document
template.Document = new DocuSignWeb.Document();
template.Document.ID = "1";
template.Document.Name = "Form Document";
template.Document.PDFBytes = <Test Document>;
template.Document.TransformPdfFields = true;
template.Document.FileExtension = "pdf";
// Create draft with all the composite template information
DocuSignWeb.EnvelopeStatus status =
_apiClient.CreateEnvelopeFromTemplatesAndForms(envelopeInfo,
new DocuSignWeb.CompositeTemplate[] { template }, false);

Schema

NameSchema TypeDescription
EnvelopeInformationEnvelopeInformationThe envelope information structure defining envelope level attributes to be used. This data will override any data that is supplied in the templates.This information is unchanged from the current schema.
CompositeTemplatesCompositeTemplateEach CompositeTemplate adds a new document and template overlays into the envelope. There can be any number of CompositeTemplate structures. Each CompositeTemplate consists of:

- ServerTemplates - 0 or more server-side templates and their position in the overlay. If supplied they are overlaid into the envelope in the order of their Sequence value. - InlineTemplates - 0 or more inline templates and their position in the overlay. If supplied they are overlaid into the envelope in the order of their Sequence value. - PDFMetaDataTemplate – 0 or 1 embedded template in the PDF meta data. If supplied the PDF meta data template will be overlaid into the envelope in the order of their Sequence value. - Document - 0 or 1 document. The document is used to specify a different document than the ones in the overlay templates. The PDF fields from this document will be transformed to Docusign Secure Fields if the TransformPdfFields option is set to true. If PDFMetaDataTemplate is supplied this is the document the template is extracted from. This information is unchanged from the current schema.

Note: Docusign will not transform PDF form fields that have the text “DocusignIgnoreTransform” or “eSignIgnoreTransform” as part of the name of the PDF form field.

See the CompositeTemplate section for rules associated with the CompositeTemplate.
ActivateEnvelopeBooleanIndicates whether the envelope should be sent immediately after being created or if it is created as a Draft Envelope.When set to “True” the envelope will be sent after being created.