You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DocuSign API Java实现:如何为签署人自动填充公司与头衔字段

Can I programmatically populate the Company and Title fields for each signer? How?

Absolutely! You can absolutely programmatically fill the Company and Title fields for each signer when sending documents via DocuSign's API—especially when working with templates. Let's walk through how to adjust your existing code to make this work:

Key Background First

Before diving into code, make sure your DocuSign template has the Company and Title fields added and linked to the corresponding signer roles (like "signer1", "signer2"). DocuSign's API lets you pass these values directly through the Signer and TemplateRole objects, which will auto-populate the fields for each signer.

Modified Code with Company/Title Population

Here's your updated code with the necessary additions (I've marked new lines with comments for clarity):

public ESenderSummary sendDocumentsToSignByOrderOfSigner(List<ESigner> eSigners, String templateId, List<EDocument> eDocuments) throws ESignException { 
    String docuSignAccountId = docuSignAuthenticationProvider.getAccountId(); 
    TemplatesApi templatesApi = docuSignAuthenticationProvider.getTemplatesApi(); 
    List<TemplateRole> templateRoles = new ArrayList<>(); 
    String emailSubject; 
    EmailSettings emailSettings; 
    Recipients recipients; 
    try { 
        EnvelopeTemplate envelopeTemplate = templatesApi.get(docuSignAccountId, templateId); 
        emailSubject = envelopeTemplate.getEmailSubject(); 
        recipients = envelopeTemplate.getRecipients(); 
        List<Signer> signers = recipients.getSigners(); 
        int index = 1; 
        for (Signer signer : signers) { 
            ESigner eSigner = eSigners.get(index - 1); 
            // create a signer recipient to sign the document, identified by name and email 
            signer.setEmail(eSigner.getEmail()); 
            signer.setName(eSigner.getFirstName() + " " + eSigner.getLastName()); 
            // NEW: Populate Company and Title for the core Signer profile
            signer.setCompany(eSigner.getCompany());
            signer.setTitle(eSigner.getTitle());

            // create a templateRole for each signer from recipient to sign the document 
            TemplateRole templateRole = new TemplateRole(); 
            templateRole.setEmail(eSigner.getEmail()); 
            templateRole.setName(eSigner.getFirstName() + " " + eSigner.getLastName()); 
            templateRole.setRoleName("signer" + index); 
            templateRole.setRoutingOrder(String.valueOf(index)); // ordering of sign 
            // NEW: Map Company and Title to the template's role-specific fields
            templateRole.setCompany(eSigner.getCompany());
            templateRole.setTitle(eSigner.getTitle());

            templateRoles.add(templateRole); 
            index++; 
        } 
        recipients.setSigners(signers); 
        emailSettings = envelopeTemplate.getEmailSettings(); 
    } catch (ApiException e) { 
        throw new ESignException("DocuSign API failed to retrieve envelope template " + templateId + ": " + e.getMessage()); 
    } 
    // Next, create the top level envelope definition and populate it. 
    EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition(); 
    envelopeDefinition.setEmailSubject(emailSubject); 
    envelopeDefinition.setRecipients(recipients); 
    envelopeDefinition.setEmailSettings(emailSettings); 
    envelopeDefinition.setTemplateRoles(templateRoles); 
    envelopeDefinition.setDocuments(createDocuments(eDocuments)); 
    return sendEnvelope(envelopeDefinition, docuSignAccountId); 
}

What's Changed & Why?

  • We added signer.setCompany() and signer.setTitle(): This fills the core signer profile details in the envelope's recipient list, ensuring the data is tied to the signer's identity.
  • We also added templateRole.setCompany() and templateRole.setTitle(): This step is critical for mapping the values to your template's role-specific fields. If your template uses role-based field assignments, this ensures the right data goes to the right fields for each signer.

Quick Checks to Avoid Issues

  • Make sure your ESigner class has getter methods for getCompany() and getTitle() (adjust the code if your signer data is stored elsewhere).
  • Double-check your DocuSign template: Confirm the Company/Title fields are assigned to the correct signer roles (e.g., fields linked to "signer1" will use values from the first TemplateRole in your list).

内容的提问来源于stack exchange,提问作者Yupanqui Munoz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 20:28:01