EnterTheCode
EnterTheCode

Reputation: 494

Can you store an email subject/body for a specific envelope type in DocuSign?

Each envelope type will have its own email subject/body that is static for that envelope type. Here is an example of a few predetermined envelope types:

These envelopes will contain a varied number of documents and each document is unique. I've attempted to create a template without a document, but it appears that is not allowed.

I'd like to be able to save the email body and subject for these envelope types so that when I send an envelope via the DocuSign API, I don't have to directly specify these fields. I'm hoping to avoid storing the subject/body inside of code or a configuration file. Preferably, I'd like a non-technical person to be able to change the subject/body through the DocuSign interface.

What I ended up doing:


Based on Kim Brandl's recommendations, I wrote the following code which worked as expected. A few notes:

  1. The initial file that you added to the template will not appear in the final envelope if the ServerTemplate sequence is greater than the InlineTemplate. You can read more here.
  2. The Recipients, signers, documents, etc., follow the same pattern as a standard EnvelopeDefinition except the data is placed under the InlineTemplate.

    string docBase64 = Convert.ToBase64String(file.Stream.ReadAsBytes());
    EnvelopeDefinition envDef = New EnvelopeDefinition();
    envDef.Status = "created";
    
    // The first sequence that appears will be the first document that is applied.
    // If you want the uploaded documents to appear instead of the server template,
    // make the server template a higher number.
    envDef.CompositeTemplates = new List<CompositeTemplate>
    {
        new CompositeTemplate()
        {
            ServerTemplates = new List<ServerTemplate>()
            {
                new ServerTemplate("2", templateId)
            },
            InlineTemplates = new List<InlineTemplate>()
            {
                new InlineTemplate()
                {
                    Sequence = "1",
                    Recipients = new Recipients()
                    {
                        Signers = new List<Signer>()
                        {
                            new Signer()
                            {
                                Email = request.Recipients[0].UserEmail,
                                Name = request.Recipients[0].UserName,
                                RoleName = request.Recipients[0].RoleName,
                                RecipientId = (1).ToString() 
                            }
                        }
                    },
                    Documents = new List<Document>()
                    {
                        new Document()
                        {
    
                            DocumentBase64 = docBase64,
                            DocumentId = "3",
                            Name = "ConsentFake.pdf",
                            IncludeInDownload = "true"
                        },
                        new Document
                        {
                            DocumentBase64 = docBase64,
                            DocumentId = "9",
                            Name = "ConsentFake2.pdf",
                            IncludeInDownload = "true"
                        }
                    }
                }
            }
        }
    };
    

Summary: This allowed me to take advantage of a DocuSign template's email subject/body without having to use a specific template document.

Upvotes: 0

Views: 351

Answers (1)

Kim Brandl
Kim Brandl

Reputation: 13500

You can implement a solution for the scenario that you've described by doing the following:

  1. Using the DocuSign web UI, create a Template for each 'type of Envelope' and specify the Email Subject and Body in each Template that you create. You'll also need to upload a document to the Template (DocuSign requires that you add at least one document before you can save the Template) -- but you can just add any placeholder doc (for example, a .txt file that contains the word placeholder file). The document you add to the template won't actually be used in the Envelopes that you create from the Template -- since you'll use the API to specify documents at runtime. (Non-technical folks will be able to use the DocuSign web UI to modify/update the email info in each Template at any point in the future.)

  2. When sending an Envelope via the API, use the compositeTemplates structure in the "Create Envelope" API request. By using the compositeTemplates structure, you can specify the serverTemplate to use (which will pull in the Email Subject and Email Body that you've defined in that Template), specify recipient and tab info by using the inlineTemplate object, and specify document info using the document object.

(There's lots of info available here on Stack Overflow about how to use compositeTemplates in the Create Envelope request. If you have trouble getting that request structure correct/working, please post a separate question.)

Upvotes: 1

Related Questions