简体   繁体   中英

How can I include multiple templates in an envelope?

I am unable to figure out how to send multiple populated DocuSign templates within an envelope using the DocuSign C# SDK. I am able to populate and send a single template within an envelope but am unable to do so with multiple templates.

This is a snippet of the code I use that successfully populates and sends the template:

var rolesList = new List<TemplateRole>();

var tRole = new TemplateRole   
{
    Tabs = new Tabs(),
    RoleName = "rolename"
};

tRole.Name = "joe smith";
tRole.Email = "email-address";

var tabData = new List<Text>();

// Populate the tabData 

tRole.Tabs.TextTabs = tabData;
rolesList.Add(tRole);

var envDef = new EnvelopeDefinition
{
    EmailSubject = "Pleae sign this",
    TemplateRoles = rolesList,
    TemplateId = "first template id",
    Status = "sent",
};

var envelopesApi = new EnvelopesApi();

await envelopesApi.CreateEnvelopeAsync("accountId", envDef);

For multiple templates, I assume I needed to use a CompositeTemplate so I tried this code:

var envDef = new EnvelopeDefinition
{
    EmailSubject = subject,
    TemplateRoles = roles,
    Status = send?  "sent" : "created",
};

var compositeTemplate = new CompositeTemplate()
{
    ServerTemplates = new List<ServerTemplate>(),
    CompositeTemplateId = Guid.NewGuid().ToString(),
};


envDef.CompositeTemplates = new List<CompositeTemplate>();
envDef.CompositeTemplates.Add(compositeTemplate);

ServerTemplate first = new ServerTemplate()
{
    TemplateId = "first template id",
    Sequence = "1"
};

ServerTemplate second = new ServerTemplate()
{
    TemplateId = "second template id",
    Sequence = "2",

};

compositeTemplate.ServerTemplates.Add(first);
compositeTemplate.ServerTemplates.Add(second);

var envelopesApi = new EnvelopesApi();

await envelopesApi.CreateEnvelopeAsync("accountId", envDef);

However, with this code the CreateEnvelopeAsync call throws the following Exception: DocuSign.eSign.Client.ApiException: Error calling CreateEnvelope: { "errorCode": "ENVELOPE_IS_INCOMPLETE", "message": "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line." }

I'm obviously not configuring the CompositeTemplate correctly (most likely not populating the Documents) but I can't seem to find an example on how to correctly populate it.

You should not mix TemplateRole and CompositeTemplate in same envelope definition as both are different design strategies. As Larry suggested, if you want to add document to be added in the envelope from two different templates, then you need to add two CompositeTemplate items. Also when you refer the Server Template, you also need to specify Inline Template to provide the RecipientRole details. In Server Template you have placeholder for the recipients but not the name and email of the recipients, so through InlineTemplate you provide the name and email of the recipient Placeholder to whom you want envelope to be addressed to.

Since your two server templates are separate from each other, I believe that you want to create an array of two composite templates. Each composite template item will contain one server template.

See line 93 and below of this example. That example sends an envelope with

  1. A template from DocuSign (a "server template")
  2. A locally created HTML source document.

In your case, repeat how item 1 is added instead of existing item 2.

The key is two different composite template items, not two server templates within one composite template item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM