2017-02-23 116 views
2

使用Docusign node.js示例我能够发送模板,但是我无法预先设置字段值。预填充docusign模板字段

我环顾堆栈溢出,发现了3个不同版本的setTemplateRoles JSON格式。我已经尝试过它们都没有工作。 当我运行此代码时,电子邮件来到[email protected],我的模板很好,但字段没有预先填充。

Q1。当他们说标签时他们在说什么?什么是标签? Q2302。 tabLabel是指数据标签,还是它们是不同的东西?

截图:
Data Label set to sellerName
编辑在GUI模板时。

Q3。如何添加“自定义字段”到我的docusign模板?我试图通过点击自定义字段,然后添加一个。但它似乎是一个比特定的自定义字段更多的字段模板。 当我运行API调用listCustomFields时,它变回空。

var docusign = require('docusign-esign'); 

// Note: Following values are class members for readability and easy testing 
// TODO: Enter your DocuSign credentials 
var UserName = '[email protected]'; 
var Password = 'SECRET1'; 

// TODO: Enter your Integrator Key (aka API key), created through your developer sandbox preferences 
var IntegratorKey = 'SECRET2'; 

// for production environment update to 'www.docusign.net/restapi' 
var BaseUrl = 'https://demo.docusign.net/restapi'; 

var RequestSignatureFromTemplate = function() { 
    // TODO: Enter signer information and template info from a template in your account 
    var signerName = 'Bob'; 
    var signerEmail = '[email protected]'; 
    var subject = "testing 123"; 
    var templateId = 'XXX'; 
    var templateRoleName = 'Seller'; 

    // initialize the api client 
    var apiClient = new docusign.ApiClient(); 
    apiClient.setBasePath(BaseUrl); 

    // create JSON formatted auth header 
    var creds = '{"Username":"' + UserName + '","Password":"' + Password + '","IntegratorKey":"' + IntegratorKey + '"}'; 
    apiClient.addDefaultHeader('X-DocuSign-Authentication', creds); 

    // assign api client to the Configuration object 
    docusign.Configuration.default.setDefaultApiClient(apiClient); 

    // =============================================================================== 
    // Step 1: Login() API 
    // =============================================================================== 
    // login call available off the AuthenticationApi 
    var authApi = new docusign.AuthenticationApi(); 

    // login has some optional parameters we can set 
    var loginOps = new authApi.LoginOptions(); 
    loginOps.setApiPassword('true'); 
    loginOps.setIncludeAccountIdGuid('true'); 
    authApi.login(loginOps, function (error, loginInfo, response) { 
    if (error) { 
     console.log('Error: ' + error); 
     return; 
    } 

    if (loginInfo) { 
     // list of user account(s) 
     // note that a given user may be a member of multiple accounts 
     var loginAccounts = loginInfo.getLoginAccounts(); 
     console.log('LoginInformation: ' + JSON.stringify(loginAccounts)); 

     // =============================================================================== 
     // Step 2: Create Envelope API (AKA Signature Request) from a Template 
     // =============================================================================== 

     // create a new envelope object that we will manage the signature request through 
     var envDef = new docusign.EnvelopeDefinition(); 
     envDef.setEmailSubject(subject); 
     envDef.setTemplateId(templateId); 
     envDef.setTemplateRoles([ 
     {email:'[email protected]', 
     name:'bob', 
     roleName:'Seller', 
     // tabStatuses:[ 
     // {tabStatus:[{ 
     // tabLabel:'sellerName', 
     // tabValue:'test123' 
     // }]} 
     // ] 

     tabs: 
     {textTabs:[{ 
      tabLabel:'sellerName', 
      tabName:'sellerName', 
      tabValue:'test123' 
     }]}, 

     // tabStatuses: 
     // {textTabs:[{ 
     // tabLabel:'sellerName', 
     // tabName:'sellerName', 
     // tabValue:'test123' 
     // }]} 

     } 
     ]); 
     // console.log("eid", envDef.getEnvelopeId()); //undefined 



     //I commented out the following example code. I looked through the docusign-esign source and it didn't seem to have a way to add tabStatuses (whatever that means) so I used the above code instead. Which works as far as sending the email, but doesn't work for pre-filling the fields. 
     // create a template role with a valid templateId and roleName and assign signer info 
     // var tRole = new docusign.TemplateRole(); 
     // tRole.setRoleName(templateRoleName); 
     // tRole.setName(signerName); 
     // tRole.setEmail(signerEmail); 
     // 
     // // create a list of template roles and add our newly created role 
     // var templateRolesList = []; 
     // templateRolesList.push(tRole); 
     // 
     // // assign template role(s) to the envelope 
     // envDef.setTemplateRoles(templateRolesList); 

     // send the envelope by setting |status| to "sent". To save as a draft set to "created" 
     envDef.setStatus('sent'); 

     // use the |accountId| we retrieved through the Login API to create the Envelope 
     var loginAccount = new docusign.LoginAccount(); 
     loginAccount = loginAccounts[0]; 
     var accountId = loginAccount.accountId; 






     //it gets a little messy with junk experimental code. But what's not commented out is the same as the example, except I've added an additional callback in the deepest function. 




     // instantiate a new EnvelopesApi object 
     var envelopesApi = new docusign.EnvelopesApi(); 

     // envelopesApi.getDocuments(loginAccount.accountId) 

     // call the createEnvelope() API 
     envelopesApi.createEnvelope(accountId, envDef, null, function (error, envelopeSummary, response) { 
     if (error) { 
      console.log('Error: ' + error); 
      return; 
     } 

     if (envelopeSummary) { 
     console.log('EnvelopeSummary: ' + JSON.stringify(envelopeSummary)); 
     var envelopeId = envelopeSummary.envelopeId; 
     console.log("envelopeId", envelopeId); 
     // envelopesApi.listDocuments(accountId, envelopeId, function (error, data, response) { 
     // if (error) {console.log("error", error);return;} 
     // console.log("data", data); 
     // console.log("response", response); 
     // }); 
     //envelopesApi.getDocument downloads the PDF binary 2.5MiB. 
     var documentId = '1'; 
     var chunks=[]; 
     envelopesApi.listCustomFields(accountId, envelopeId, function (error, data, response) { 
      if (error) {console.log("error", error);return;} 
      console.log("typeof data", typeof data); 
      // console.log("data.length", data.length); 
      // // console.log("response", response); 
      // response.on('data',chunk => chunks.push(chunk)); 
      // response.on('end',()=>{ 
      // var allChunks = chunks.join(''); 
      // console.log("allChunks", allChunks); 
      // }); 
      console.log("data", data); 
      // console.log("data.toJson()", data.toJson()); 
      console.log("data.getTextCustomFields()", data.getTextCustomFields()); 
     }); 

     } 

     }); 
    } 
    }); 
}; // end RequestSignatureFromTemplate() 

回答

1

当他们说标签他们在说什么?什么是标签?

选项卡 - 又名字段或标签 - 可以添加到文档和模板中,并有多种使用方式。

  • 首先它们用于指示接收者需要签名或首字母缩写。其次,它们可用于向收件人显示数据或信息,如日期,名称,地址和其他数据。
  • 第三,标签可用于为可编辑信息字段,以便您可以从您的收件人检索数据或信息

更多信息here


不tabLabel意味着数据标签,或者是他们不同的东西?

是的,他们是一样的。

如果您在收件人更新一个选项卡时将相同类型的选项卡设为同一个tabLabel,它将实时更新具有相同数据的所有其他选项卡。

更多信息here(请参阅 “共享选项卡标签” 一节)


我怎么能一个 “自定义字段” 添加到我的DocuSign模板?我试图通过点击自定义字段,然后添加一个。但它似乎是一个比特定的自定义字段更多的字段模板。当我运行API调用listCustomFields时,它变回空。

“自定义字段”可能意味着几件事情。 有关更多信息,请参阅此answer

如果您在处理文档寻找标签,那么你应该探索listEnvelopeTabs API


我的模板来通过罚款,但字段不会预先填写。

如果您正在寻找预填字段(aka Tabs),则应在请求中设置“”值“属性。更多信息here

这是原始的Json请求。

"tabs": { 
"textTabs": [ 
    { 
    "value": "$100", 
    "xPosition": "300", 
    "yPosition": "200", 
    "documentId": "1", 
    "pageNumber": "1" 
    }] 
} 
+1

Sorted!非常感谢 – Josh