Search code examples
docusignapidocusigncompositetmplts

Docusign Composite template pre populating tab values


I am using Docusign Java Rest client library. I have a server template with simple text fields. I want to send esignature request from my program, with pre populated data in the form, so that the recipient won't have to fill those fields.

My code snippet:

    EnvelopeDefinition envDef = new EnvelopeDefinition();
    envDef.setEmailSubject("ATTACHMENT TESTING");

    List<CompositeTemplate> compositeTemplates = new ArrayList<>();
    envDef.setCompositeTemplates(compositeTemplates);

    CompositeTemplate t1 = new CompositeTemplate();

    List<ServerTemplate> serverTemplates = new ArrayList<>();
    t1.setServerTemplates(serverTemplates);

    ServerTemplate st = new ServerTemplate();
    st.setSequence("1");
    st.setTemplateId("8as3232a-ea84-448d-852b-7617bf4d1759");
    serverTemplates.add(st);

    CompositeTemplate t2 = new CompositeTemplate();

    List<InlineTemplate> inlineTemplates = new ArrayList<>();
    t2.setInlineTemplates(inlineTemplates);

    InlineTemplate it = new InlineTemplate();
    it.setSequence("2");
    inlineTemplates.add(it);

    Document doc = new Document();
    doc.setDocumentId("2");
    doc.setName("SSN Copy");
    doc.setRemoteUrl("https://images.pexels.com/photos/10656/c4f497772338464a5d4e4109966e02f7.jpg");
    doc.setFileExtension("jpeg");
    t2.setDocument(doc);

    compositeTemplates.add(t1);
    compositeTemplates.add(t2);

    List<TemplateRole> templateRoles = new ArrayList<>();
    TemplateRole templateRole = new TemplateRole();

    templateRole.setRoleName("Customer");
    templateRole.setName(currentUser.getDisplayName());
    templateRole.setEmail(currentUser.getEmail());

    /********Prepopulating data to fields.
    Tabs tabs = new Tabs();

    Text text1 = new Text();
    text1.setTabLabel("firstName");
    text1.setValue("Adams");
    tabs.getTextTabs().add(text1);

    Text text2 = new Text();
    text2.setTabLabel("lastName");
    text2.setValue("Johnson");
    tabs.getTextTabs().add(text2);

    templateRole.setTabs(tabs);

    templateRoles.add(templateRole);

    // assign template role(s) to the envelope
    envDef.setTemplateRoles(templateRoles);

    envDef.setStatus("sent");

    // instantiate a new EnvelopesApi object
    EnvelopesApi envelopesApi = new EnvelopesApi();

    // call the createEnvelope() API
    try {
        EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envDef);
    } catch (ApiException e) {
        e.printStackTrace();
    }

But the form goes to the recipient, without any value I filled. Fields are blank. Am I doing this wrong? Please help.


Solution

  • You are mixing two different DocuSign design patterns, i.e you should not mix Composite Template and TemplateRole.

    Template Role is needed when you have one server template and you want to prepopulate the signer information and/or any DocuSign tab information present in the template from your application.

    Whereas Composite template can do what a templaterole design can do and over that it can do lot of other stuffs like if you have multiple server templates and want to use all of them in one envelope then you need composite template, or when you want to mix server template with in-flight document then you need composite template. Proper Example of Composite template is available at https://stackoverflow.com/a/20036349/3530898

    In your case, if you have only one server template and if document to your envelope will be provided by your server template only then you just need to user TemplateRole. I could not understand what is the use of passing a document SSN Copy, is is a document which customer needs to sign?