1

I have a template in Docusign that I need to send to joe@acme.com

However Joe is responsible for managing 10 clients and instead of me sending Joe 10 separate envelopes for him to sign I want to send Joe 1 envelope with 10 documents and Joe needs to sign all 10 document in the envelope. The documents are identical except for the different data filled in the text field of the template

I am using the C# SDK provided by Docusign and I can send one document in an envelope using EnvelopeDefinition class and TemplateRole class but am lost as to how to create 10 documents in an envelope

The following recipe does it but it is in python and uses the REST API with which I am not sure how to translate to the C# SDK equivalent https://www.docusign.com/developer-center/recipes/send-multiple-docs

Larry K
  • 47,808
  • 15
  • 87
  • 140
kurasa
  • 5,205
  • 9
  • 38
  • 53

2 Answers2

4

You can use compositeTemplates and reuse the same server template multiple times in the envelope. The below code uses the same server Template and repeats it 10 times in the envelope. See full example here

public void CreateEnvelope()
{
  var envDef = new EnvelopeDefinition()
  {
      EmailSubject = "Envelope with multiple documents",
      Status = "sent",
      CompositeTemplates = new List<CompositeTemplate>()
  };

  for (int docNumber = 1; docNumber <= 10; docNumber++)
  {
      var compostiteTemplate = BuildCompositeTemplate(docNumber.ToString());
      envDef.CompositeTemplates.Add(compostiteTemplate);

  }

  EnvelopesApi envelopesApi = new EnvelopesApi();
  EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
  Console.WriteLine(envelopeSummary);
}

public CompositeTemplate BuildCompositeTemplate(string docNumber)
{
    string serverTemplateId = "";//Add your server template ID here
    return new CompositeTemplate()
    {
          ServerTemplates = new List<ServerTemplate>()
          {
              new ServerTemplate()
              {
                  TemplateId = serverTemplateId,
                  Sequence = docNumber
              }
          },
          InlineTemplates = new List<InlineTemplate>()
          {
              new InlineTemplate()
              {
                  Sequence = docNumber,
                  Recipients = new Recipients()
                  {
                      Signers = new List<Signer>()
                      {
                          new Signer()
                          {
                              Email = "Janedoe@acme.com",
                              Name = "Jane Doe",
                              RecipientId = "1",
                              RoleName = "Signer1",
                              Tabs = new Tabs()
                              {
                                  TextTabs = new List<Text>()
                                  {
                                      new Text()
                                      {
                                          DocumentId = docNumber,
                                          PageNumber = "1",
                                          XPosition = "100",
                                          YPosition = "100",
                                          Width = 120, 
                                          Value = "Some Tab Value " + docNumber
                                      }
                                  }

                              }
                          }
                      }
                  }
              }
          }
    }
}
Praveen Reddy
  • 7,295
  • 2
  • 21
  • 43
1

There is the property Documents in the class EnvelopeDefinition, where you can add multiply documents.

I use the REST API Explorer from DocuSign when I want to check how to implement a feature.

            enDef = new EnvelopeDefinition();
            doc = new Document();

            doc.DocumentBase64 = System.Convert.ToBase64String(System.IO.File.ReadAllBytes(filename));
            doc.Name = DocName;
            doc.DocumentId = "1"; // increment this

            enDef.Documents = new List<Document>();
            enDef.Documents.Add(doc);

Added

For multiply template roles also exists a property called TemplateRoles in the EnvelopeDefinition. There you can add more than one.

            tempRole = new TemplateRole();
            tempRole.Name = Rolename;

            enDef.TemplateRoles = new List<TemplateRole>();
            enDef.TemplateRoles.Add(tempRole);`
  • thanks. I saw the Document collection but it wants a document but I'd like to be able to populate a template. Possible? If I could create document from the template this would work – kurasa Jun 06 '17 at 11:20
  • have you tried this? I tried adding another template role but the result was that there was one document only with the information from the second templaterole only...I dont think this is what the TemplateRole is for – kurasa Jun 06 '17 at 11:30
  • I think perhaps your original answer is correct. From what I can see the only way to do this is by adding documents to an envelope as a template already has the documents defined. Like I said if I could populate a template and have it return a document then I'd add that to the document collection of the envelope nut I can't see how to do that – kurasa Jun 06 '17 at 11:39