Problems creating a DocuSign envelope using a template & editing recipients email before sending

62 Views Asked by At

Goal

Hey, I have a scenario in which I want to create an envelope based on a template, and I want to give our users the ability to change the name & email of the recipients specified in the template.

This is how my code currently looks like

            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,
            })

Problem

Everything works fine except that the envelope is sent to both recipients, the original one and the edited one.

I made sure to only edit the recipient's (signer) email or name, and not the recipientId.

this is how looks like

    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;
    }

I copied the recipient info from what's returned in the template.

Previous attempts

Also, before trying the Composite Template approach, I was using the standard approach of sending an envelope based on a template, but adding editing the recipients inline in the envelope still caused the duplication issue, which is why I tried the alternative Composite template approach.

[Edit]

snippet in docs titled: Merging duplicate recipients

https://developers.docusign.com/docs/esign-rest-api/esign101/concepts/templates/composite/

Here's a snippet in the DocuSign docs regarding merging duplicate recipients.

It says:

You can automatically merge these duplicate recipients by making sure that each of these duplicate recipients has the same email, user name, and routing order

Does that mean that I cannot edit the base template's recipient's email at all? Maybe there's another approach outside of composite templating?

Thanks for reading.

1

There are 1 best solutions below

3
On

You're specifying the server template twice.

Here's a live example you can try.

Try this envelope request:

         {
            status: "sent",
            compositeTemplates: [
                {
                    compositeTemplateId: "1",
                    serverTemplates: [
                        {
                            sequence: "1",
                            templateId: templateId
                        }
                    ],
                    inlineTemplates: [
                        {
                            sequence: "1",
                            recipients: {
                                signers: [
                                    {
                                        email: email,
                                        name: name,
                                        roleName: "Signer1",
                                        recipientId: "1",
                                    }
                                ]
                            }
                        }
                    ]
                }
            ]
        };