通过 DocuSign API 调用 CreateEnvelopeFromTemplates,您如何将收件人与模板中的角色相匹配?

With the DocuSign API call CreateEnvelopeFromTemplates how do you match a recipient with the role in the template?

我的模板定义了一个角色。我正在尝试根据模板发送一个信封,并为该角色填写姓名和电子邮件,这样用户就不必放置自己的签名块。

问题是它向信封添加了第二个签名者。然后,收到要求他们签名的电子邮件的第二个签名者必须手动放置他们的签名,因为签名块仅为第一个签名者定义。

我从这里的代码开始:https://www.docusign.com/p/APIGuide/Content/Sending%20Group/CreateEnvelopeFromTemplates.htm

这是我的代码。这是 Java 代码。

            // just get the first template for now
            EnvelopeTemplates templates = port.requestTemplates(accountId, false);
            String templateId = templates.getEnvelopeTemplateDefinition().get(0).getTemplateID();
            EnvelopeTemplate template = port.requestTemplate(templateId, false);

            // get the existing recipient from the template
            Recipient recipient = template.getEnvelope().getRecipients().getRecipient().get(0);
            recipient.setEmail("asdf@example.com");
            recipient.setUserName("John Doe");
            ArrayOfRecipient1 recipients = new ArrayOfRecipient1();
            recipients.getRecipient().add(recipient);

            ArrayOfCustomField arrayOfCustomField = new ArrayOfCustomField();
            CustomField f = new CustomField();
            f.setName("masterRecordId");
            f.setValue("1");
            f.setShow("false");
            arrayOfCustomField.getCustomField().add(f);

            // define envelope info
            EnvelopeInformation envelopeInformation = new EnvelopeInformation();
            envelopeInformation.setSubject("test email subject");
            envelopeInformation.setAccountId(accountId);
            envelopeInformation.setEmailBlurb("test email blurb");
            envelopeInformation.setCustomFields(arrayOfCustomField);

            // define template
            ArrayOfTemplateReference arrayOfTemplateReference = new ArrayOfTemplateReference();
            TemplateReference templateReference = new TemplateReference();
            templateReference.setTemplate(template.getEnvelopeTemplateDefinition().getTemplateID());
            templateReference.setTemplateLocation(TemplateLocationCode.SERVER);
            arrayOfTemplateReference.getTemplateReference().add(templateReference);
            EnvelopeStatus status = port.createEnvelopeFromTemplates(arrayOfTemplateReference, recipients, envelopeInformation, false);

如果您已经在模板中定义了收件人角色,则需要引用该角色,而不是在代码中创建一个新角色。我认为这两个收件人是 1 个来自模板 + 1 个来自代码。

设置 recipient.roleName 以匹配您在模板中为其指定的名称。

缺少的部分是您还必须添加 TemplateReferenceRoleAssignment。这是那段代码:

            TemplateReferenceRoleAssignment trra = new TemplateReferenceRoleAssignment();
            trra.setRoleName("Stake holder");
            trra.setRecipientID(recipientId);
            templateReference.getRoleAssignments().getRoleAssignment().add(trra);

以下是完整的工作代码:

            // create envelope from template
            EnvelopeTemplates templates = port.requestTemplates(accountId, false);
            String templateId = templates.getEnvelopeTemplateDefinition().get(0).getTemplateID();
            EnvelopeTemplate template = port.requestTemplate(templateId, false);

            ArrayOfCustomField arrayOfCustomField = new ArrayOfCustomField();
            CustomField f = new CustomField();
            f.setName("masterRecordId");
            f.setValue("1");
            f.setShow("false");
            arrayOfCustomField.getCustomField().add(f);

            // define envelope info
            EnvelopeInformation envelopeInformation = new EnvelopeInformation();
            envelopeInformation.setSubject("test email subject");
            envelopeInformation.setAccountId(accountId);
            envelopeInformation.setEmailBlurb("test email blurb");
            envelopeInformation.setCustomFields(arrayOfCustomField);

            // define template
            TemplateReference templateReference = new TemplateReference();
            templateReference.setRoleAssignments(new ArrayOfTemplateReferenceRoleAssignment());
            templateReference.setTemplate(template.getEnvelopeTemplateDefinition().getTemplateID());
            templateReference.setTemplateLocation(TemplateLocationCode.SERVER);

            BigInteger recipientId = BigInteger.valueOf(1);

            // define the recipient info
            Recipient recipient = new Recipient();
            recipient.setID(recipientId);
            recipient.setEmail("jane@example.org");
            recipient.setUserName("Jane Doe");
            recipient.setType(RecipientTypeCode.SIGNER);
            ArrayOfRecipient1 recipients = new ArrayOfRecipient1();
            recipients.getRecipient().add(recipient);

            // this links the recipient above with the role in the template
            TemplateReferenceRoleAssignment trra = new TemplateReferenceRoleAssignment();
            trra.setRoleName("Stake holder");
            trra.setRecipientID(recipientId);
            templateReference.getRoleAssignments().getRoleAssignment().add(trra);

            // make the API call to send off the envelope
            ArrayOfTemplateReference arrayOfTemplateReference = new ArrayOfTemplateReference();
            arrayOfTemplateReference.getTemplateReference().add(templateReference);
            EnvelopeStatus status = port.createEnvelopeFromTemplates(arrayOfTemplateReference, recipients, envelopeInformation, true);