0
votes

Issue: I am creating an envelope definition, assigning a templateID to it that contains 4 documents. Depending on the use case, I may only want to send out 2 of those documents. In this case my code adds the 2 documents I want to the envelope definition from the template. The document tags are then populated with data. I check the documents in the envelope definition before setting it's status to "sent" and there are only 2 documents. When I go to Docusign to sign the documents after sending, all 4 documents are there, not just the 2 that I want. Is there any way around this? I'd really rather not create a separate template for all of the permutations of documents, and re-create the tags in all of the template documents as well. If there is an easier way of creating templates and document tags, maybe a way to copy documents into different templates, please let me know.

Code example:

    DSBase test = new DSBase(ApiClient);

            test.CheckToken();
            TemplatesApi temp = new TemplatesApi(ApiClient.Configuration);

            EnvelopeTemplateResults tempResults = temp.ListTemplates(AccountID);
            EnvelopeTemplate ETemplate = new EnvelopeTemplate();
            EnvelopeDefinition edef = new EnvelopeDefinition();
            edef.Documents = new List<Document>();
//This gets the template I am interested in. Currently there is only
//one template I am working with, it contains 4 documents.
            ETemplate = temp.Get(DSConfig.TargetAccountID, tempResults.EnvelopeTemplates.FirstOrDefault().TemplateId);

edef.TemplateId = ETemplate.TemplateId;

 foreach (DataRow docRow in documentRows)
            {
                Document doc = ETemplate.Documents.Find(X => X.Name == docRow["DOCUMENTNAME"].ToString());

//There is code here to populate the tabs on the document
//Then the document is added to the envelope definition
edef.Documents.Add(doc);
//For this particular contract only 2 documents are added to the Envelope
//However when the signer receives the Docusign notification, 
//all 4 documents from the template are present to be signed.

edef.Status = "created";
            int docCount = edef.Documents.Count; //Count only shows 2 documents
            edef.Status = "sent";
           
            EnvelopeSummary results = eApi.CreateEnvelope(DSConfig.TargetAccountID, edef);

}

1
Can you provide any code samples for what you are doing? - Tubs
Code sample added. - PECOPig

1 Answers

0
votes

First, you can only remove them before the envelope is sent. So you need to keep "created" like you had and do a PUT to update to "sent" after you do something like this:

eApi.DeleteDocuments(DSConfig.TargetAccountID, edef.EnvelopeId, new EnvelopeDefinition{ Documents = new List<Document>);

Where you provide the list of documents to delete.

(note the EnvelopeDefinition here should just have the documents you want to remove, not anything else).