Reputation: 65
I'm working in the sandbox and have a template saved with a PDF that I've created fields for. I'm trying to pre-fill these fields based on some conditions, and then send the template out to be signed. I'm using the UpdateTabs method and passing in a list of the tabs for the template, including the TabId, which I've looped through and changed the value for.
When the template gets sent after this, the fields are all blank. Is this a limitation of the sandbox environment, or am I doing this incorrectly?
Here's the code for creating the template draft, grabbing the tabs, updating the tabs, then sending the draft:
var roles = recipients
.Select((role, i) =>
{
var templateRole = role.MapTo<TemplateRole>();
templateRole.RoutingOrder = $"{i + 1}";
return templateRole;
})
.ToList();
var envelope = new EnvelopeDefinition(
TemplateId: templateId,
TemplateRoles: roles,
Status: DocuSignConstants.Statuses.Created);
var envelopeApi = new EnvelopesApi(_docuSignClient.Client.Configuration);
var result = await envelopeApi
.CreateEnvelopeAsync(_docuSignContext.Account.AccountId, envelope)
.ConfigureAwait(false);
var template = await GetDocuSignTemplateById(templateId);
// Grabbing the tabs from the template and then updating the values in them
var tabs = await GetDocumentTabs(templateId, template.Documents.First().DocumentId);
SetDocumentTabValues(recordId, templateId, template.Documents.First().DocumentId, tabs);
var draftRecipients = await envelopeApi.ListRecipientsAsync(_docuSignContext.Account.AccountId,
result.EnvelopeId);
foreach (var signer in draftRecipients.Signers)
{
envelopeApi.UpdateTabs
(
_docuSignContext.Account.AccountId,
result.EnvelopeId,
signer.RecipientId,
tabs
);
}
envelopeApi.Update(_docuSignContext.Account.AccountId, result.EnvelopeId, new Envelope
{
Status = DocuSignConstants.Statuses.Sent
});
And here's where I'm setting the value for the tabs (text tabs in this case):
var tab = tabs.TextTabs?.FirstOrDefault(x => x.TabLabel == field.TemplateField);
if (tab != null)
{
tab.OriginalValue = fieldValue;
tab.Value = fieldValue;
}
I tried setting both the Value and the OriginalValue fields, but neither of them sets the fields. It comes in blank with a warning in the upper right saying "DEMONSTRATION DOCUMENT ONLY", which makes me wonder if I just can't set the tabs in the sandbox.
Upvotes: 0
Views: 546
Reputation: 65
I figured out the issue: I was grabbing the tabs from the template's documents instead of calling the ListTabs function on each recipient. Once I grabbed those tabs instead, setting the values works perfectly.
foreach (var signer in draftRecipients.Signers)
{
var signerTabs = await envelopeApi
.ListTabsAsync(_docuSignContext.Account.AccountId,
result.EnvelopeId,
signer.RecipientId);
SetDocumentTabValues(recordId, templateId, template.Documents.First().DocumentId, signerTabs);
envelopeApi.UpdateTabs
(
_docuSignContext.Account.AccountId,
result.EnvelopeId,
signer.RecipientId,
signerTabs
);
}
Upvotes: 2