如何使用Docusign Java API发送给多个收件人?

时间:2018-03-01 16:29:45

标签: docusignapi

我有一个角色名称为“申请人”的Docusign模板。和“共同申请人”。在签名页面上有一个标签,供每个人签名。

我正在尝试使用Java API将文档一个接一个地发送给两个收件人,这样他们每个人都可以登录各自的标签,但我遇到了几个问题。

以下是我的代码。我遇到的问题如下:

1)如果我在.setRoleName调用中使用实际角色名称,则在到达createEnvelope行时会出现TAB_REFERS_TO_MISSING_DOCUMENT错误。

2)如果我使用新的角色名称(例如,“申请人1”和“共同申请人1”),则电子邮件将被发送给有权访问两个签名字段的申请人。当他们签字时,文件就完成了,而且它永远不会送给共同申请人。

我无法弄清楚我做错了什么。任何能够帮助我的人都会如此善良吗?谢谢!

<Initializations>
envDef = new EnvelopeDefinition();
CompositeTemplate tCompositeTemplate = new CompositeTemplate();
Document document = new Document();

tCompositeTemplate.setDocument(document);
tCompositeTemplate.getDocument().setDocumentBase64(Base64.encodeBase64String(fileBytes));
tCompositeTemplate.getDocument().setName("<docName>");
tCompositeTemplate.getDocument().setDocumentId(1);
tCompositeTemplate.getDocument().setTransformPdfFields("true");
tCompositeTemplate.getDocument().setFileExtension("pdf");

java.util.List<Document> docs = new ArrayList<Document>();
docs.add(tCompositeTemplate.getDocument());
envDef.setDocuments(docs);

Signer signerApp = new Signer();
signerApp.setEmail("<appEmail>");
signerApp.setName("<appName>");
signerApp.setRecipientId("1");
signerApp.setRoutingOrder("1");

Signer signerCoapp = new Signer();
signerCoapp.setEmail("<coappEmail>");
signerCoapp.setName("<coappName>");
signerCoapp.setRecipientId("2");
signerCoapp.setRoutingOrder("2");

java.util.List<SignHere> signHereTabs = new ArrayList<SignHere>();

SignHere signHereApp = new SignHere();
signHereApp.setDocumentId(tCompositeTemplate.getDocument().getDocumentId());
signHereApp.setRecipientId("1");
signHereApp.setTabLabel("\\*primary_app_sig_2_DocuSignSignHere");
signHereTabs.add(signHereApp);

SignHere signHereCoapp = new SignHere();
signHereCoapp.setDocumentId(tCompositeTemplate.getDocument().getDocumentId());
signHereCoapp.setRecipientId("2");
signHereCoapp.setTabLabel("\\*co_app_sig_2_DocuSignSignHere");
signHereTabs.add(signHereCoapp);

Tabs tabs = new Tabs();
tabs.setSignHereTabs(signHereTabs);
signerApp.setTabs(tabs);
signerCoapp.setTabs(tabs);

tRoleApp = new TemplateRole();
tRoleApp.setEmail("<Email>");
tRoleApp.setName("<Name>");
tRoleApp.setRoleName("Applicant");

tRoleCoApp= new TemplateRole();
tRoleCoApp.setEmail("<Email>");
tRoleCoApp.setName("<Name>");
tRoleCoApp.setRoleName("Co-applicant");

java.util.List<TemplateRole> rolesList = new ArrayList<>();
rolesList.add(tRoleApp);
rolesList.add(tRoleCoApp);
envDef.setTemplateId("<templateID>");
envDef.setTemplateRoles(rolesList);

envDef.getTemplateRoles().get(0).setTabs(new Tabs());
envDef.getTemplateRoles().get(0).getTabs().setSignHereTabs(new ArrayList<SignHere>());
envDef.getTemplateRoles().get(0).getTabs().getSignHereTabs().add(signHereApp);    

envDef.getTemplateRoles().get(1).setTabs(new Tabs());
envDef.getTemplateRoles().get(1).getTabs().setSignHereTabs(new ArrayList<SignHere>());
envDef.getTemplateRoles().get(1).getTabs().getSignHereTabs().add(signHereCoapp);

EnvelopesApi envelopesApi = new EnvelopesApi();
envelopeSummary = envelopesApi.createEnvelope(<"acctID">, envDef);

2 个答案:

答案 0 :(得分:0)

根据您帖子的措辞,听起来您通过DocuSign网络用户界面创建的模板已经包含文档,标签和收件人角色信息(例如,收件人角色名称和路由顺序)。如果是这种情况,那么您不需要在Create Envelope API请求中指定文档和标签信息 - 您只需要为每个收件人指定TEMPLATE_ID和信息(角色名称,姓名和电子邮件)。以下代码示例说明了此方法。

// create a new envelope definition object 
EnvelopeDefinition envDef = new EnvelopeDefinition();

// specify the ID of the template that contains the document, recipient roles, tabs, etc.
envDef.setTemplateId("TEMPLATE_ID");

// specify info for first recipient (applicant)
TemplateRole tRole1 = new TemplateRole();
tRole1.setRoleName("Applicant");
tRole1.setName("APPLICANT_NAME");
tRole1.setEmail("APPLICANT_EMAIL");

// specify info for second recipient (co-applicant)
TemplateRole tRole2 = new TemplateRole();
tRole2.setRoleName("Co-applicant");
tRole2.setName("CO-APPLICANT_NAME");
tRole2.setEmail("CO-APPLICANT_EMAIL");

// add recipient info to the envelope definition
java.util.List<TemplateRole> templateRolesList = new java.util.ArrayList<TemplateRole>();
templateRolesList.add(tRole1);
templateRolesList.add(tRole2);
envDef.setTemplateRoles(templateRolesList);

// set status to "sent" so that the Envelope will be sent when the API request is issued
envDef.setStatus("sent");

// issue the Create Envelope API request to create/send the Envelope
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envDef);

(如果我误解了您的方案并且 是您需要在Create Envelope请求中指定文档和标签信息的原因,请在此答案中添加评论,我将提供有关如何实现这一目标的信息。)

答案 1 :(得分:0)

您正在混合两种DocuSign设计或策略模式,一种是TemplateRole,另一种是CompositeTemplate。您不应将两者混合在同一个EnvelopeDefinition Call中。 Composite Template是推荐的设计方法,因为它涵盖了TemplateRole中未涵盖的所有方案。例如,如果您有一个场景需要在单个信封中添加多个DS Server模板或ServerTemplate和运行时文档的混合,那么您唯一的解决方案是复合模板。因此,始终使用Composite Template创建解决方案,因为它是最强大的设计模式并涵盖所有方案。

<Initializations> envDef = new EnvelopeDefinition(); CompositeTemplate tCompositeTemplate = new CompositeTemplate(); Signer signerApp = new Signer(); signerApp.setEmail("<appEmail>"); signerApp.setName("<appName>"); signerApp.setRecipientId("1"); signerApp.setRoutingOrder("1"); signerApp.setRoleName("Applicant"); Signer signerCoapp = new Signer(); signerCoapp.setEmail("<coappEmail>"); signerCoapp.setName("<coappName>"); signerCoapp.setRecipientId("2"); signerCoapp.setRoutingOrder("2"); signerCoapp.setRoleName("Co-applicant"); //Below code is required if you want to pass a document in the composite //template, either to replace the document present in the server Template //or you do not have a server template Document document = new Document(); tCompositeTemplate.setDocument(document); tCompositeTemplate.getDocument().setDocumentBase64(Base64.encodeBase64String(fileBytes)); tCompositeTemplate.getDocument().setName("<docName>"); tCompositeTemplate.getDocument().setDocumentId(1); tCompositeTemplate.getDocument().setTransformPdfFields("true"); tCompositeTemplate.getDocument().setFileExtension("pdf"); java.util.List<SignHere> signHereTabs = new ArrayList<SignHere>(); SignHere signHereApp = new SignHere(); signHereApp.setDocumentId(tCompositeTemplate.getDocument().getDocumentId()); signHereApp.setRecipientId("1"); signHereApp.setTabLabel("\\*primary_app_sig_2_DocuSignSignHere"); signHereTabs.add(signHereApp); SignHere signHereCoapp = new SignHere(); signHereCoapp.setDocumentId(tCompositeTemplate.getDocument().getDocumentId()); signHereCoapp.setRecipientId("2"); signHereCoapp.setTabLabel("\\*co_app_sig_2_DocuSignSignHere"); signHereTabs.add(signHereCoapp); Tabs tabs = new Tabs(); tabs.setSignHereTabs(signHereTabs); signerApp.setTabs(tabs); signerCoapp.setTabs(tabs); Recipients recipients = new Recipients(); List<Signer> signers = new ArrayList<Signer>(); signers.add(signerApp); signers.add(signerCoapp); recipients.setSigners(signers); InlineTemplate inlineTemplate = new InlineTemplate(); inlineTemplate.setRecipients(recipients); inlineTemplate.setSequence("2"); List<InlineTemplate> inlineTemplateList = new ArrayList<InlineTemplate>(); inlineTemplateList.add(inlineTemplate); tCompositeTemplate.setInlineTemplates(inlineTemplateList); //Below ServerTemplate is required if you have server template //and all the signer tabs are already added in the server template ServerTemplate serverTemplate = new ServerTemplate(); serverTemplate.setSequence("1"); serverTemplate.setTemplateId("SERVER_TEMPLATE_ID"); List<ServerTemplate> serverTemplateList = new ArrayList<ServerTemplate>(); serverTemplateList.add(serverTemplate); tCompositeTemplate.setServerTemplates(serverTemplateList); //Adding ServerTemplate to compositeTemplate finishes here List<CompositeTemplate> compositeTemplateList = new ArrayList<CompositeTemplate>(); compositeTemplateList.add(tCompositeTemplate); envDef.setCompositeTemplates(compositeTemplateList); EnvelopesApi envelopesApi = new EnvelopesApi(); envelopeSummary = envelopesApi.createEnvelope(<"acctID">, envDef); 的有效示例是:

#data frame definitions
data1 <- data.frame(HHID = c(100,100,100,200,200), blockid = c(1,2,1,1,1), serial_number = c(1,2,3,1,2), name = c('xxx', 'yyy', 'zzz', 'sss', 'ddd'))
data2 <- data.frame(HHID = c(100,200), serial = c(3,2), hospital = c('Delphi', 'paris'))

#unique identifier
data1$unique <- paste(data1$HHID, data1$serial_number, sep = '')
data2$unique <- paste(data2$HHID, data2$serial, sep = '')