Populate Dropdown options using c# code in a docus

2019-07-31 01:04发布

问题:

I have create a template in my Admin Account Panel, and I am using the template to create new envelopes and send to different receivers. But in my template I have a dropdown whose value changes on some condition, like for State A it will have different values, for State B it will have different values. How do I handle it programmatically. Here is how I create an envelope from a template.

        string recipientEmail = "a@a.com";
        string recipientName = "John Doe";
        string templateRoleName = "Customer";
        string TemplateId = "xxxxxxxx-c87454e95429";

        EnvelopeDefinition envDef = new EnvelopeDefinition();
        envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";

        // assign recipient to template role by setting name, email, and role name.  Note that the
        // template role name must match the placeholder role name saved in your account template.  
        TemplateRole tRole = new TemplateRole();
        tRole.Email = recipientEmail;
        tRole.Name = recipientName;
        tRole.RoleName = templateRoleName;

        List<TemplateRole> rolesList = new List<TemplateRole>() { tRole };

        // add the role to the envelope and assign valid templateId from your account
        envDef.TemplateRoles = rolesList;
        envDef.TemplateId = TemplateId;

        // set envelope status to "sent" to immediately send the signature request
        envDef.Status = "sent";

        // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
        EnvelopesApi envelopesApi = new EnvelopesApi(cfi);
       EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);

回答1:

To populate tabs in a template you must match the name of the tab using the tabLabel property and set its value to the data you want to populate it with

Documentation here

string recipientEmail = "a@a.com";
 string recipientName = "John Doe";
 string templateRoleName = "Customer";
 string TemplateId = "xxxxxxxx-c87454e95429";

 EnvelopeDefinition envDef = new EnvelopeDefinition();
 envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";

// assign recipient to template role by setting name, email, and role name.  Note that the
// template role name must match the placeholder role name saved in your account template.  
var tRole = new TemplateRole();
tRole.Email = recipientEmail;
tRole.Name = recipientName;
tRole.RoleName = templateRoleName;

var dropdownItems = new List<ListItem>();

if (stateA)
{
    dropdownItems.Add(new ListItem()
    {
        Text = "Yellow", Value = "Y", Selected = "true"
    });
    dropdownItems.Add(new ListItem()
    {
        Text = "Green",Value = "G"
    });
}
else
{
    dropdownItems.Add(new ListItem()
    {
        Text = "Red", Value = "R", Selected = "true"
    });
    dropdownItems.Add(new ListItem()
    {
        Text = "Blue", Value = "B"
    });
    dropdownItems.Add(new ListItem()
    {
        Text = "Orange", Value = "O"
    });
}

tRole.Tabs = new Tabs()
{
    ListTabs = new List<List>()
    {
        new List(){
            TabLabel = "ColorDropdown",
            ListItems = dropdownItems
        }
    }
};

var rolesList = new List<TemplateRole>() { tRole };

// add the role to the envelope and assign valid templateId from your account
envDef.TemplateRoles = rolesList;
envDef.TemplateId = TemplateId;

// set envelope status to "sent" to immediately send the signature request
envDef.Status = "sent";

// |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
EnvelopesApi envelopesApi = new EnvelopesApi();
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);


标签: docusignapi