docusign / docusign-esign-java-client

The Official Docusign Java Client Library used to interact with the eSignature REST API. Send, sign, and approve documents using this client.
https://javadoc.io/doc/com.docusign/docusign-esign-java/latest/index.html
MIT License
105 stars 97 forks source link

I want to send an envelope via the template, but the pre-submit tab doesn't work #236

Closed yuyu414 closed 2 years ago

yuyu414 commented 2 years ago

I want to send an envelope via the template, but the pre-submit tab doesn't work, I uploaded the document and set the template here, but the files in the template are preset. For example, there is a company name in my official document. I need to set it in advance and let the user sign it. The following code is invalid. `package com.docusign.jwtconsoleapp;

import com.docusign.esign.model.PrefillTabs; import com.docusign.esign.model.TemplateRole; import com.docusign.esign.model.Text;

import com.docusign.esign.api.EnvelopesApi; import com.docusign.esign.client.ApiClient; import com.docusign.esign.client.auth.OAuth.OAuthToken; import com.docusign.esign.client.auth.OAuth.UserInfo; import com.docusign.esign.client.ApiException; import com.docusign.esign.model.EnvelopeDefinition; import com.docusign.esign.model.EnvelopeSummary; import com.docusign.esign.model.Tabs;

import java.nio.file.Files; import java.nio.file.Paths; import java.util.; import java.io.;

/**

public class JWTConsoleApp {

static String DevCenterPage = "https://developers.docusign.com/platform/auth/consent";

/**
 * Application entry point.
 *
 * @param args application command line arguments
 */
public static void main(String[] args) throws java.io.IOException {

    System.out.println("Welcome to the JWT Code example! ");
    // Get information fro app.config
    Properties prop = new Properties();
    String fileName = "app.config";
    FileInputStream fis = new FileInputStream(fileName);
    prop.load(fis);
    try {
        // Get access token and accountId
        ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
        apiClient.setOAuthBasePath("account-d.docusign.com");
        ArrayList<String> scopes = new ArrayList<String>();
        scopes.add("signature");
        scopes.add("impersonation");
        byte[] privateKeyBytes = Files.readAllBytes(Paths.get(prop.getProperty("rsaKeyFile")));
        OAuthToken oAuthToken = apiClient.requestJWTUserToken(prop.getProperty("clientId"), prop.getProperty("userId"), scopes, privateKeyBytes, 3600);
        String accessToken = oAuthToken.getAccessToken();
        UserInfo userInfo = apiClient.getUserInfo(accessToken);
        String accountId = userInfo.getAccounts().get(0).getAccountId();
        System.out.println("accountId=" + accountId);

        String signerEmail = "8888888@qq.com";
        String signerName = "签名者";
        WorkArguments arguments = new WorkArguments();
        arguments.setSignerEmail(signerEmail);
        arguments.setSignerName(signerName);
        arguments.setTemplateId("36e443ad-8410-422f-8558-def07b1d445f");
        Object doWork = doWork(arguments, accessToken, "https://demo.docusign.net/restapi");

        System.out.println("doWork=" + doWork);
    } catch (Exception e) {
        System.out.print("Error!!!  ");
        System.out.print(e.getMessage());
    }
}

protected static Object doWork(WorkArguments args, String accessToken, String basePath) throws ApiException {
    ApiClient apiClient = new ApiClient(basePath);
    apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken);
    EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
    EnvelopeDefinition envelope = makeEnvelope(args);
    EnvelopeSummary result = envelopesApi.createEnvelope("598d7ac6-1de0-4b13-ada1-a06634634a9f", envelope);
    System.out.println("The envelope has been created and sent!<br/>Envelope ID " + result.getEnvelopeId() + ".");
    return result;
}

private static EnvelopeDefinition makeEnvelope(WorkArguments args) {
    String signerEmail = args.getSignerEmail();
    String signerName = args.getSignerName();
    String templateId = args.getTemplateId();

    EnvelopeDefinition env = new EnvelopeDefinition();
    env.setTemplateId(templateId);

    TemplateRole signer1 = new TemplateRole();
    signer1.setEmail(signerEmail);
    signer1.setName(signerName);
    signer1.setRoleName("signer");

    Tabs tabs = new Tabs();
    PrefillTabs prefillTabs = new PrefillTabs();
    ArrayList<Text> list = new ArrayList<>();
    Text text = new Text();
    text.setTabLabel("Text b43e23c9-f007-41f9-892b-15fa8a586a2b");
    text.setName("kkkkkkkkkkkkkk");
    text.setValue("uuuuuuuuuuuuuuuuu");
    text.setDocumentId("1");
    text.setPageNumber("1");
    list.add(text);
    prefillTabs.setTextTabs(list);
    tabs.setPrefillTabs(prefillTabs);
    signer1.setTabs(tabs);

    env.setTemplateRoles(Arrays.asList(signer1));
    env.setStatus("sent");
    return env;
}

}`

image image

yuyu414 commented 2 years ago

Why no preset information is generated image

smd9788 commented 2 years ago

@yuyu414 You are not able to set the value of prefillTabs when creating an envelope. You will need to use ordinary textTabs to accomplish setting a text value when creating an envelope. In your template, you can set these textTabs to read-only if you wish to keep the text value fixed.

yuyu414 commented 2 years ago

@yuyu414 You are not able to set the value of prefillTabs when creating an envelope. You will need to use ordinary textTabs to accomplish setting a text value when creating an envelope. In your template, you can set these textTabs to read-only if you wish to keep the text value fixed.

image Modification to this still does not take effect, how can I access it?

smd9788 commented 2 years ago

@yuyu414 - I was able to create a simple text tab in my own app using the following code:

Text text = new Text();
text.setDocumentId("1");
text.setPageNumber("1");
text.setXPosition("191");
text.setYPosition("348");
text.setName("textTab1");
text.setValue("this is the value of the text tab");
Tabs tabs = new Tabs();
tabs.setTextTabs(Arrays.asList(text));

I tried to use your code, but don't know what the 'WorkArguments' object is, so can't run the code. It does look like you are using the correct setter methods on the 'text' object, but I suspect you are not getting or setting your Template correctly, which would mean the 'tabs.setTabLabel' isn't mapping to a template tab.

yuyu414 commented 2 years ago

@yuyu414- 我能够使用以下代码在我自己的应用程序中创建一个简单的文本选项卡:

Text text = new Text();
text.setDocumentId("1");
text.setPageNumber("1");
text.setXPosition("191");
text.setYPosition("348");
text.setName("textTab1");
text.setValue("this is the value of the text tab");
Tabs tabs = new Tabs();
tabs.setTextTabs(Arrays.asList(text));

我尝试使用您的代码,但不知道“WorkArguments”对象是什么,因此无法运行代码。看起来您在“文本”对象上使用了正确的 setter 方法,但我怀疑您没有正确获取或设置模板,这意味着“tabs.setTabLabel”没有映射到模板选项卡。

I have solved it thanks

dijiehuang commented 2 years ago

@yuyu414 你好,遇到跟你一样的问题。想从模板里写预填充字段值,请问最后是怎么解决的?hello, I have the same problem as you. I want to write the pre-filled field value from the template. What is the final solution?

yuyu414 commented 2 years ago

@yuyu414 你好,遇到跟你一样的问题。想从模板里写预填充字段值,请问最后是怎么解决的?hello, I have the same problem as you. I want to write the pre-filled field value from the template. What is the final solution?

你的代码贴出来,注意模板的rolename的和代码里的rolename要对应上 image

dijiehuang commented 2 years ago

@yuyu414 你好,遇到跟你一样的问题。想从模板里写预填充字段值,请问最后是怎么解决的?hello, I have the same problem as you. I want to write the pre-filled field value from the template. What is the final solution?

你的代码贴出来,注意模板的rolename的和代码里的rolename要对应上 image

    TemplateRole signer = new TemplateRole();
    signer.setEmail(signerEmail);
    signer.setName(signerName);
    signer.setRoleName("甲方");

    // 甲方预填充字段标签:a5045fac-9679-498a-a73c-6c255dfccc49
    Tabs tabs = new Tabs();
    PrefillTabs prefillTabs = new PrefillTabs();
    List<Text> textTabs = new ArrayList<>();
    Text text = new Text();
    text.setValue("djdj");
    text.setTabLabel("a5045fac-9679-498a-a73c-6c255dfccc49");
    text.setDocumentId("1");
    text.setPageNumber("1");

    textTabs.add(text);
    prefillTabs.setTextTabs(textTabs);
    tabs.setPrefillTabs(prefillTabs);
    signer.setTabs(tabs);

@yuyu414 模板的rolename的和代码里的rolename是一样的

yuyu414 commented 2 years ago

@yuyu414 你好,遇到跟你一样的问题。想从模板里写预填充字段值,请问最后是怎么解决的?hello, I have the same problem as you. I want to write the pre-filled field value from the template. What is the final solution?

你的代码贴出来,注意模板的rolename的和代码里的rolename要对应上 image

    TemplateRole signer = new TemplateRole();
    signer.setEmail(signerEmail);
    signer.setName(signerName);
    signer.setRoleName("甲方");

    // 甲方预填充字段标签:a5045fac-9679-498a-a73c-6c255dfccc49
    Tabs tabs = new Tabs();
    PrefillTabs prefillTabs = new PrefillTabs();
    List<Text> textTabs = new ArrayList<>();
    Text text = new Text();
    text.setValue("djdj");
    text.setTabLabel("a5045fac-9679-498a-a73c-6c255dfccc49");
    text.setDocumentId("1");
    text.setPageNumber("1");

    textTabs.add(text);
    prefillTabs.setTextTabs(textTabs);
    tabs.setPrefillTabs(prefillTabs);
    signer.setTabs(tabs);

@yuyu414 模板的rolename的和代码里的rolename是一样的

看你的web页面的模板编辑一下 看一下那里面会设置签发的rolename 看看是不是甲方?

dijiehuang commented 2 years ago

@yuyu414 你好,遇到跟你一样的问题。想从模板里写预填充字段值,请问最后是怎么解决的?hello, I have the same problem as you. I want to write the pre-filled field value from the template. What is the final solution?

你的代码贴出来,注意模板的rolename的和代码里的rolename要对应上 image

    TemplateRole signer = new TemplateRole();
    signer.setEmail(signerEmail);
    signer.setName(signerName);
    signer.setRoleName("甲方");

    // 甲方预填充字段标签:a5045fac-9679-498a-a73c-6c255dfccc49
    Tabs tabs = new Tabs();
    PrefillTabs prefillTabs = new PrefillTabs();
    List<Text> textTabs = new ArrayList<>();
    Text text = new Text();
    text.setValue("djdj");
    text.setTabLabel("a5045fac-9679-498a-a73c-6c255dfccc49");
    text.setDocumentId("1");
    text.setPageNumber("1");

    textTabs.add(text);
    prefillTabs.setTextTabs(textTabs);
    tabs.setPrefillTabs(prefillTabs);
    signer.setTabs(tabs);

@yuyu414 模板的rolename的和代码里的rolename是一样的

看你的web页面的模板编辑一下 看一下那里面会设置签发的rolename 看看是不是甲方?

image

预填充文本不是不能选择收件人吗?

dijiehuang commented 2 years ago

image

image

有的,角色都有

yuyu414 commented 2 years ago

那我不知道了 你可以下载一下demo项目跑一下

dijiehuang commented 2 years ago

demo里没有预填充的例子。你最后用的是PrefillTabs 还是 textTabs ?

dijiehuang commented 2 years ago

@yuyu414 可以发下你那边的代码example吗?我本地对比下看看