C# DocusignAPI Composite template with tabs on server template

320 Views Asked by At

I am using the Embedded Signing Ceremony from a template with an added document code example 13 and am trying to add tabs to my composite template. I have added some test fields and values as is from the code examples (on this page) to prefill my server template. But the values are not showing in the recipient view when testing.

Apologies if this is an easy one. But can someone please help me work out what I might be missing or configuring wrong?

This is the C# code that I am testing for this right now.

public Eg013AddDocToTemplateController(DSConfiguration config, IRequestItemsService requestItemsService) 
    : base(config, requestItemsService)
{
}

public override string EgName => "eg013";

// ***DS.snippet.0.start
private string DoWork(string signerEmail, string signerName, string ccEmail,
    string ccName, string accessToken, string basePath,
    string accountId, string item, string quantity, string dsReturnUrl)
{
    // Data for this method
    // signerEmail 
    // signerName
    // ccEmail
    // ccName
    // item
    // quantity
    // accessToken
    // basePath 
    // accountId 
    // dsReturnUrl
    var config = new Configuration(new ApiClient(basePath));
    config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
    EnvelopesApi envelopesApi = new EnvelopesApi(config);

    // Step 1. Make the envelope request body
    EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName, ccEmail, ccName, item, quantity);

    // Step 2. call Envelopes::create API method
    // Exceptions will be caught by the calling function
    EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelope);
    String envelopeId = results.EnvelopeId;
    Console.WriteLine("Envelope was created. EnvelopeId " + envelopeId);

    // Step 3. create the recipient view, the Signing Ceremony
    RecipientViewRequest viewRequest = MakeRecipientViewRequest(signerEmail, signerName, dsReturnUrl);
    ViewUrl results1 = envelopesApi.CreateRecipientView(accountId, envelopeId, viewRequest);
    return results1.Url;
}


private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName, 
    string dsReturnUrl)
{
    // Data for this method
    // signerEmail 
    // signerName
    // dsReturnUrl
    // signerClientId -- class global

    RecipientViewRequest viewRequest = new RecipientViewRequest
    {
        // Set the url where you want the recipient to go once they are done signing
        // should typically be a callback route somewhere in your app.
        ReturnUrl = dsReturnUrl,

        // How has your app authenticated the user? In addition to your app's
        // authentication, you can include authenticate steps from DocuSign.
        // Eg, SMS authentication
        AuthenticationMethod = "none",

        // Recipient information must match embedded recipient info
        // we used to create the envelope.
        Email = signerEmail,
        UserName = signerName,
        ClientUserId = signerClientId
    };

    // DocuSign recommends that you redirect to DocuSign for the
    // Signing Ceremony. There are multiple ways to save state.

    return viewRequest;
}

private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string ccEmail, 
    string ccName, string item, string quantity)
{
    // Data for this method
    // signerEmail 
    // signerName
    // ccEmail
    // ccName
    // item
    // quantity
    // signerClientId -- class global


    // The envelope request object uses Composite Template to
    // include in the envelope:
    // 1. A template stored on the DocuSign service
    // 2. An additional document which is a custom HTML source document

    // Create Recipients for server template. Note that Recipients object
    // is used, not TemplateRole
    //
    // Create a signer recipient for the signer role of the server template
    Signer signer1 = new Signer
    {
        Email = signerEmail,
        Name = signerName,
        RoleName = "signer",
        RecipientId = "1",
        // Adding clientUserId transforms the template recipient
        // into an embedded recipient:
        ClientUserId = signerClientId
    };
    // Create the cc recipient
    CarbonCopy cc1 = new CarbonCopy
    {
        Email = ccEmail,
        Name = ccName,
        RoleName = "cc",
        RecipientId = "2"
    };
    // Recipients object:
    Recipients recipientsServerTemplate = new Recipients
    {
        CarbonCopies = new List<CarbonCopy> { cc1 },
        Signers = new List<Signer> { signer1 }
    };

    // create a composite template for the Server Template
    CompositeTemplate compTemplate1 = new CompositeTemplate
    {
        CompositeTemplateId = "1"
    };
    ServerTemplate serverTemplates = new ServerTemplate
    {
        Sequence = "1",
        TemplateId = RequestItemsService.TemplateId
    };

    compTemplate1.ServerTemplates = new List<ServerTemplate> { serverTemplates };
    // Add the roles via an inlineTemplate
    InlineTemplate inlineTemplate = new InlineTemplate
    {
        Sequence = "2",
        Recipients = recipientsServerTemplate
    };
    compTemplate1.InlineTemplates = new List<InlineTemplate> { inlineTemplate };
    // The signer recipient for the added document with
    // a tab definition:
    SignHere signHere1 = new SignHere
    {
        AnchorString = "**signature_1**",
        AnchorYOffset = "10",
        AnchorUnits = "pixels",
        AnchorXOffset = "20"
    };

    Text textLegal = new Text
    {
        AnchorString = "/legal/",
        AnchorUnits = "pixels",
        AnchorYOffset = "-9",
        AnchorXOffset = "5",
        Font = "helvetica",
        FontSize = "size11",
        Bold = "true",
        Value = "Legal Name",
        Locked = "false",
        TabId = "legal_name",
        TabLabel = "text",
    };

    Text textFamiliar = new Text
    {
        AnchorString = "/familiar/",
        AnchorUnits = "pixels",
        AnchorYOffset = "-9",
        AnchorXOffset = "5",
        Font = "helvetica",
        FontSize = "size11",
        Bold = "true",
        Value = signerName,
        Locked = "false",
        TabId = "familiar_name",
        TabLabel = "Familiar name"
    };

    // The salary is set both as a readable number in the /salary/ text field,
    // and as a pure number in a custom field ('salary') in the envelope
    int salary = 123000;

    Text textSalary = new Text
    {
        AnchorString = "/salary/",
        AnchorUnits = "pixels",
        AnchorYOffset = "-9",
        AnchorXOffset = "5",
        Font = "helvetica",
        FontSize = "size11",
        Bold = "true",
        Locked = "true",
        // Convert number to String: 'C2' sets the string 
        // to currency format with two decimal places
        Value = salary.ToString("C2"),
        TabId = "salary",
        TabLabel = "Salary"
    };


    Tabs signer1Tabs = new Tabs
    {
        SignHereTabs = new List<SignHere> { signHere1 }
    };
    // Signer definition for the added document
    Signer signer1AddedDoc = new Signer
    {
        Email = signerEmail,
        Name = signerName,
        ClientUserId = signerClientId,
        RoleName = "signer",
        RecipientId = "1",
        Tabs = signer1Tabs
    };
    // Recipients object for the added document:
    Recipients recipientsAddedDoc = new Recipients
    {
        CarbonCopies = new List<CarbonCopy> { cc1 },
        Signers = new List<Signer> { signer1AddedDoc }
    };

    // create the HTML document
    Document doc1 = new Document();
    
    String doc1b64 = Convert.ToBase64String(document1(signerEmail, signerName, ccEmail, ccName, item, quantity));
    doc1.DocumentBase64 = doc1b64;
    doc1.Name = "Membership form"; // can be different from actual file name
    doc1.FileExtension = "html";
    doc1.DocumentId = "1";
    // create a composite template for the added document
    CompositeTemplate compTemplate2 = new CompositeTemplate
    {
        CompositeTemplateId = "1"
    };
    // Add the recipients via an inlineTemplate
    InlineTemplate inlineTemplate2 = new InlineTemplate
    {
        Sequence = "2",
        Recipients = recipientsAddedDoc
    };
    compTemplate2.InlineTemplates = new List<InlineTemplate> { inlineTemplate2};
    compTemplate2.Document = doc1;

    EnvelopeDefinition env = new EnvelopeDefinition
    {
        Status = "sent",
        CompositeTemplates = new List<CompositeTemplate> { compTemplate1, compTemplate2 }
    };

    return env;
}
1

There are 1 best solutions below

3
On BEST ANSWER

You've created a lot of tabs, but you haven't assigned them to the signer in question.

Tabs signer1Tabs = new Tabs
{
    SignHereTabs = new List<SignHere> { signHere1 }
};

Under the line for SignHereTabs, you need to add

TextTabs = new List<Text> { }

with all of your text tabs between the curly braces.

As a side note, if the tags you are filling in are on the Server Template, you only need the tabLabel and value parameters to populate them. Any other parameter should be removed. But if you are adding new tabs in your API call, then what you have is correct.