0

I'm trying to apply a template (not use a template) using the .NET SDK and I can't seem to get it. I have seen one or two other articles on here but neither is using the SDK. Can anyone help me solve this using the SDK?

My situation is this: I have a template defined that contains all of my anchor tags with placement info. When I apply the template via the UI, it works fine and the tags get placed appropriately. When I upload the same document via the API, the tags are not applied.

I have tried to replicate what is shown in these articles using Composite Templates with no success:

In one of the articles, the OP said the envelope needed to be a Draft. I tried that, but then I haven't been able to change it to "sent" after that.

Here's some of the relevant code from my ASP.NET Web Forms test project. In this project, I'm using a asp:FileUpload control to grab the file contents and then I call the SendFileToDocusign() method:

    private void SendFileToDocusign(byte[] fileData, string accessToken)
    {
        //Create a signer recipient to sign the document, identified by name and email
        //We set the clientUserId to enable embedded signing for the recipient
        Signer tmpSigner1 = new Signer {
            Email = "me@me.com", Name = "Test Tester",
            ClientUserId = "1000", RecipientId = "1", RoleName = "Signer1", CustomFields = new List<string> { "Buyer1" }
        };

        //Step 1. Create the envelope definition
        EnvelopeDefinition tmpEnvDef = MakeEnvelopeAndApplyTemplate(fileData, new List<Signer> { tmpSigner1 });

        //Step 2. Call DocuSign to create the envelope           
        ApiClient tmpClient = new ApiClient(DOCUSIGN_API_BASEPATH);
        tmpClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
        EnvelopesApi tmpEnvelopesApi = new EnvelopesApi(tmpClient);
        EnvelopeSummary tmpResults = tmpEnvelopesApi.CreateEnvelope(DOCUSIGN_ACCOUNTID, tmpEnvDef);
        string tmpEnvelopeID = tmpResults.EnvelopeId;

        //Step 3. create the recipient view, the Signing Ceremony
        RecipientViewRequest tmpViewRequest = MakeRecipientViewRequest(tmpSigner1);
        //call the CreateRecipientView API
        ViewUrl tmpRecipView = tmpEnvelopesApi.CreateRecipientView(DOCUSIGN_ACCOUNTID, tmpEnvelopeID, tmpViewRequest);

       Response.Redirect(tmpRecipView.Url);
    } 

    private EnvelopeDefinition MakeEnvelopeAndApplyTemplate(byte[] fileData, List<Signer> signers)
    {
        EnvelopeDefinition tmpEnv = new EnvelopeDefinition(EmailSubject:"We don't really use the Subject Line here");
        Document tmpDoc = new Document();
        Recipients tmpRecipients = new Recipients(Signers:signers);
        CompositeTemplate tmpCompTemplate = new CompositeTemplate("1");

        string tmpfileDataB64 = Convert.ToBase64String(fileData);

        tmpDoc.DocumentBase64 = tmpfileDataB64;
        tmpDoc.Name = "Test file";//can be different from actual file name
        tmpDoc.FileExtension = "pdf";
        tmpDoc.DocumentId = "1";

        InlineTemplate tmpInlineTemplate = new InlineTemplate();
        tmpInlineTemplate.Sequence = "1";
        tmpInlineTemplate.Recipients = tmpRecipients;

        ServerTemplate tmpServerTemplate = new ServerTemplate("2", DOCUSIGN_TEMPLATE_ID);

        tmpCompTemplate.ServerTemplates = new List<ServerTemplate>() { tmpServerTemplate };
        tmpCompTemplate.InlineTemplates = new List<InlineTemplate>() { tmpInlineTemplate };
        tmpCompTemplate.Document = tmpDoc;

        tmpEnv.CompositeTemplates = new List<CompositeTemplate>() { tmpCompTemplate };

        //Request that the envelope be sent by setting |status| to "sent".
        //To request that the envelope be created as a draft, set to "created"
        tmpEnv.Status = "sent";

        return tmpEnv;
    }

Thanks for any help you can offer.

Eric
  • 3
  • 1

1 Answers1

0

Your code has to handle the recipients correctly. The roleName must match between recipients pre-defined in the template and the ones you add in your code. I don't see in your code that part. The example you use is for composite template. The relevant code for this is in a regular template example but it's the same.

https://github.com/docusign/code-examples-csharp/blob/master/launcher-csharp/eSignature/Controllers/Eg009UseTemplateController.cs

TemplateRole signer1 = new TemplateRole();
                signer1.Email = signerEmail;
                signer1.Name =  signerName;
                signer1.RoleName = "signer";
    
                TemplateRole cc1 = new TemplateRole();
                cc1.Email = ccEmail;
                cc1.Name = ccName;
                cc1.RoleName = "cc";
Inbar Gazit
  • 12,566
  • 1
  • 16
  • 23
  • Thanks Inbar for getting me on the right track. Actually it wasn't necessary to use TemplateRole, I just needed to make sure the RoleName in my Signer object matched. I didn't know that's how it linked it together. The RoleName I was using was just some arbitrary text. – Eric Oct 06 '20 at 19:30