我正在沙盒中工作,并保存了一个模板,该模板与我为其创建字段的PDF一起保存。我正在尝试根据某些条件预填充这些字段,然后将模板发送出去以进行签名。我正在使用UpdateTabs方法,并传入模板的选项卡列表,包括TabId,我已遍历并更改了其值。
此后发送模板时,所有字段均为空白。这是沙箱环境的限制,还是我做错了?
以下是用于创建模板草稿,抓取标签,更新标签并发送草稿的代码:
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
});
这是我在其中设置标签(在这种情况下为文本标签)的值的地方:
var tab = tabs.TextTabs?.FirstOrDefault(x => x.TabLabel == field.TemplateField);
if (tab != null)
{
tab.OriginalValue = fieldValue;
tab.Value = fieldValue;
}
我尝试同时设置“值”和“原始值”字段,但是它们都不设置字段。它是空白的,右上方有一个警告,上面写着“仅演示文档”,这使我想知道是否无法设置沙箱中的标签。
答案 0 :(得分:2)
我发现了问题:我从模板文档中抓取选项卡,而不是在每个收件人上调用ListTabs函数。相反,一旦我抓住了这些标签,就可以完美地设置值。
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
);
}