嘿,我有一个场景,我想基于模板创建一个信封,并且我想让我们的用户能够更改模板中指定的收件人的姓名和电子邮件。
这就是我的代码目前的样子
const compositeTemplate = docusign.CompositeTemplate.constructFromObject({
serverTemplates: [
// @ts-expect-error exists
docusign.ServerTemplate.constructFromObject({
sequence: 1,
templateId,
})
],
inlineTemplates: [
// @ts-expect-error exists
docusign.InlineTemplate.constructFromObject({
templateId,
sequence: 2,
recipients: this.serializeUpdateRecipients(signers),
})
]
});
// @ts-expect-error exists
const envelopeDefinition = docusign.EnvelopeDefinition.constructFromObject({
status: "sent",
compositeTemplates: [compositeTemplate],
})
const envelopesApi = new docusign.EnvelopesApi(this.client);
const envelope = await envelopesApi.createEnvelope(this.userInfo.accounts[0].accountId, {
envelopeDefinition,
})
一切正常,只是信封被发送给两个收件人,即原始收件人和编辑后的收件人。
我确保只编辑收件人(签名者)的
email
或 name
,而不是 recipientId
。
这就是看起来的样子
private serializeUpdateRecipients(signers: Signer[]) {
// @ts-expect-error Docusign @types are not up to date
const recipients = new docusign.Recipients();
recipients.signers = signers.map(({ name, email, tabs, roleName, recipientId, routingOrder }) => (
// @ts-expect-error Docusign @types are not up to date
new docusign.Signer.constructFromObject({
email,
name,
roleName,
recipientId,
routingOrder,
tabs,
})
));
return recipients;
}
我从模板中返回的内容中复制了收件人信息。
此外,在尝试复合模板方法之前,我使用的是基于模板发送信封的标准方法,但是在信封中添加内联编辑收件人仍然会导致重复问题,这就是为什么我尝试了替代的复合模板方法.
https://developers.docusign.com/docs/esign-rest-api/esign101/concepts/templates/composite/
这是 DocuSign 文档中有关合并重复收件人的片段。
它说:
您可以通过确保每个重复收件人都具有相同的电子邮件、用户名和路由顺序来自动合并这些重复收件人
这是否意味着我根本无法编辑基本模板的收件人电子邮件?也许除了复合模板之外还有另一种方法?
感谢您的阅读。
您指定了服务器模板两次。
这是一个实例你可以尝试一下。
尝试这个信封请求:
{
status: "sent",
compositeTemplates: [
{
compositeTemplateId: "1",
serverTemplates: [
{
sequence: "1",
templateId: templateId
}
],
inlineTemplates: [
{
sequence: "1",
recipients: {
signers: [
{
email: email,
name: name,
roleName: "Signer1",
recipientId: "1",
}
]
}
}
]
}
]
};