0

I'm experimenting with the DocuSign REST SDK (nuget package) and am having trouble getting custom fields returned with the Envelope metadata. I've tried creating an Envelope using a composite template with custom fields as part of both the Inline Template and the Envelope Definition just to see what I can get back:

CompositeTemplate composite = new CompositeTemplate();
            composite.Document = document;
            InlineTemplate inlineTemplate = new InlineTemplate();
            inlineTemplate.Sequence = "1";
            inlineTemplate.Recipients = new Recipients();
            inlineTemplate.Recipients.Signers = new List<Signer>();
            inlineTemplate.Recipients.Signers.Add(signer);

            inlineTemplate.CustomFields = new CustomFields(null, new List<TextCustomField>());
            TextCustomField iCF = new TextCustomField();
            iCF.Name = "InlineTemplateCustomField";
            iCF.Value = "202303";

            inlineTemplate.CustomFields.TextCustomFields.Add(iCF);

            ServerTemplate serverTemplate = new ServerTemplate("2", "8e556cd1-d343-4c07-9401-d88b00a67671"); //payment template id

            composite.InlineTemplates = new List<InlineTemplate>();
            composite.InlineTemplates.Add(inlineTemplate);
            composite.ServerTemplates = new List<ServerTemplate>();
            composite.ServerTemplates.Add(serverTemplate);

            EnvelopeDefinition envDef = new EnvelopeDefinition();
            envDef.CompositeTemplates = new List<CompositeTemplate>();
            envDef.CompositeTemplates.Add(composite);

            TextCustomField cf = new TextCustomField();
            cf.Name ="EnvelopeCustomField";
            cf.Value = "101202";

            envDef.CustomFields = new CustomFields(null, new List<TextCustomField>());
            envDef.CustomFields.TextCustomFields.Add(cf);

            ApiClient apiClient = new ApiClient(basePath);
            apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
            EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);
            EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envDef);

I can retrieve the InlineTemplateCustomField using the ListCustomFields method but if I retrieve the Envelope results with the "custom_fields" option the Envelope's custom fields array will be null. Is this expected?

CustomFieldsEnvelope customFieldsEnvelope = envelopesApi.ListCustomFields(accountId, "743e9d25-e093-43ec-acbd-5fbfce053e92");
EnvelopesApi.GetEnvelopeOptions options = new EnvelopesApi.GetEnvelopeOptions();
options.include = "custom_fields";
Envelope results = envelopesApi.GetEnvelope(accountId, "743e9d25-e093-43ec-acbd-5fbfce053e92", options);

I would prefer to get the Envelope's status and custom fields in one API call if possible, which is why I was hoping to get the "EnvelopeCustomField" back in the GetEnvelope call.

1 Answers1

0

I would suggest you take a look at the code example that shows you how to do this. The C# code can be found here:

https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg018EnvelopeCustomFieldDataController.cs

relevant lines of code:

EnvelopesApi envelopesApi = new EnvelopesApi(config);
CustomFieldsEnvelope results = envelopesApi.ListCustomFields(accountId, envelopeId);
Inbar Gazit
  • 12,566
  • 1
  • 16
  • 23
  • Hi Inbar, thanks for your response. I am using the ListCustomFields method in the code that I posted, but that only returns the custom fields added as part of the Inline Template, not the custom fields added as part of the Envelope Definition. I expected these lines to get the custom fields added to the Envelope Definition – user2705063 Dec 09 '19 at 13:50
  • This documentation led me to believe that I could use EnvelopesApi.GetEnvelopeOptions to cause GetEnvelope to return custom fields: https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/get I tried it in the last 3 lines of my posted codes but results.CustomFields is null whether I pass in the 'options' object or not. – user2705063 Dec 09 '19 at 13:57
  • are you talking about account custom fields? that is on the Account level, I can show you the code to get these if that's what you mean – Inbar Gazit Dec 09 '19 at 18:00
  • look at AccountsAPI.cs, it has a method to get custom fields – Inbar Gazit Dec 09 '19 at 18:00