Você está na página 1de 13

How to Use the DocuSign Automation Script Loader Mechanism

How to write a script in NetSuite

To start, you may use your favorite text editor to type out the code. Save it as a text file anywhere in
your computer and rename the file extension to .js. Instead of writing the script from scratch, you may
choose to copy one of the sample scripts shown in the appendix. Feel free to modify any of the sample
scripts to your liking.

Note that you do not need to configure any NetSuite settings for automation scripts (e.g. you do not
have to include any additional files or set the NetSuite script type for that file).
Saving the script into NetSuite

Go to the NetSuite File Cabinet section and click on the Add File button.

The script should now appear in the folder.


Configuring the DocuSign Custom Button

Go to the DocuSign configuration page (i.e. the DocuSign Account Settings page). Select on one of the
record types you would like the button to appear (lets say we want the new button to be in
Opportunity). Click on the Add New Custom Button link.

A popup will appear. You may enter whatever you would like for the button label. After selecting the
folder, select the script in the file list. Only file with extension .js will show up in the file list.
Running the script

Go to the record where you have placed the button (in this example, it was Opportunity). Click on the
newly made button. The script should now run.

Appendix

List of DocuSign functions available for NetSuite Automation Scripts

docusignGetRecipients(docusignContext, orderNumber, idBegin, fileNum)

This function will retrieve all the contacts that are associated with the current NetSuite record.

Parameters

docusignContext {object} [required] An opaque object that contains various information about
the current context. This object is passed into the automation script as docusignContext. Do
not assume the structure of its contents.
orderNumber {integer} [optional] A positive number to use as the routing number. Each
recipient will be assigned the same routing number.
idBegin {integer} [optional] A positive number to begin the sequence of id numbers for each
recipient with. For example, lets say there are 3 recipients saved in the NetSuite records. If the
number 3 is passed in through this parameter, then the first recipient will have the id number
3, the second recipient will have the id number 4, and the third recipient will have the id
number 5.
fileNum {integer} [optional] A positive number to indicate which file the recipient(s) will be
added to. Each recipient will be assigned the same file number. For example, lets say there are
3 files (a document, an attachment and a template). If the number 2 is passed in through this
parameter, all the recipients will be added to the attachment file. This parameter is used only
when sending with DocuSign template.

docusignGetFiles(docusignContext)

This function will retrieve all the documents that are associated with the current NetSuite record.

Parameters

docusignContext {object} [required] An opaque object that contains various information about
the current context. This object is passed into the automation script as docusignContext. Do
not assume the structure of its contents.

docusignGetEmail(docusignContext)
This function will retrieve the email object that is associated with the current NetSuite record type. The
email object includes the default email subject and message.

Parameters

docusignContext {object} [required] An opaque object that contains various information about
the current context. This object is passed into the automation script as docusignContext. Do
not assume the structure of its contents.

docusignPopulateEnvelope(docusignContext , recipients, files, email)

This function will populate a DocuSign envelope with the given arguments and present it to the user. It
will return an object containing the view URL that is embedded in an iframe.

Parameters

docusignContext {object} [required] An opaque object that contains various information about
the current context. This object is passed into the automation script as docusignContext. Do
not assume the structure of its contents.
recipients {array} [optional] An array of Recipient objects. The return value of
docusignGetRecipients() may be passed into this parameter. The structure of the Recipient
object is this:
o id {integer} The unique id number of the recipient. It is used by the tab element to
indicate which recipient is to sign the Document.
o order {integer} The routing priority number (lesser value means more important).
o name {string} The full name of the recipient.
o email {string} The email address of the recipient.
o role {integer} The DocuSign role of the recipient. It can be used to map to a recipient
in the template.
o fileNum {integer} This number is used to indicate which file the recipient should be
added to.
files {array} [optional] An array of File objects. The return value of docusignGetFiles() may be
passed into this parameter. There are 3 types of file object: document, template and
attachment. The structure of the File object is this:
o Document {default, use when type is not passed}
name {string} The name of the file (extension included).
content {string} The files content encoded in base64. Its size should be less
than 5 megabytes (which is NetSuites file size limit).
o Template {type: template}
id {string} The DocuSign Template id
signers {array} [optional] An array of Signer objects. It can be used to add
signer(s) to the template. The structure of the Signer object is this:
id {integer} The unique id number of the recipient. It is used by the tab
element to indicate which recipient is to sign the Document.
order {integer} The routing priority number (lesser value means more
important).
name {string} The full name of the recipient.
email {string} The email address of the recipient.
role {string} The role of the recipient
o Attachment {type: attachment}
searches {array} [optional] An array of Search objects. It can be used to search
for particular attachment(s). The structure of the search is this:
keyword {string} The keyword of the search
type {string} The search types: exact, board or phase
email { object } [optional] An objects that contains the default email subject and message. The
structure of the Email object is this:
o subject { string } The default email subject of the current record type.
o blurb {string} The default email message of the current record type.

docusignSignEnvelope(docusignContext , files, email)

This function will create a DocuSign envelope with the given arguments and present it to the user for
him or her to sign. It will return an object containing the view URL that is embedded in an iframe.

Parameters

docusignContext {object} [required] An opaque object that contains various information about
the current context. This object is passed into the automation script as docusignContext. Do
not assume the structure of its contents.
files {array} [optional] An array of File objects. The return value of docusignGetFiles() may be
passed into this parameter. There are 3 types of file object: document, template and
attachment. The structure of the File object is this:
o Document {default, use when type is not passed}
name {string} The name of the file (extension included).
content {string} The files content encoded in base64. Its size should be less
than 5 megabytes (which is NetSuites file size limit).
o Template {type: template}
id {string} The DocuSign Template id
role {string} The role of the signer
o Attachment {type: attachment}
searches {array} [optional] An array of Search objects. It can be used to search
for particular attachment(s). The structure of the search is this:
keyword {string} The keyword of the search
type {string} The search types: exact, board or phase

o name {string} The name of the file (extension included).


o content {string} The files content encoded in base64. Its size should be less than 5
megabytes (which is NetSuites file size limit).
email { object } [optional] An objects that contains the default email subject and message. The
structure of the Email object is this:
o subject { string } The default email subject of the current object type.
o blurb {string} The default email message of the current object type.

Sample Scripts

minimalSend.js

function minimalSendMain() {
var recipients = docusignGetRecipients(docusignContext);
var files = docusignGetFiles(docusignContext);
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

minimalSign.js

function minimalSignMain() {
var files = docusignGetFiles(docusignContext);
return docusignSignEnvelope(docusignContext, files);
}

tax.js

function taxMain() {
var res = nlapiRequestURL('http://www.irs.gov/pub/irs-pdf/fw4.pdf');
var recipients = docusignGetRecipients(docusignContext);
var files = [{ name: 'w4.pdf', content: res.getBody() }];
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

atom.js

var minimalPdf =
'JVBERi0xLjENCiXCpcKxw6sNCg0KMSAwIG9iag0KICA8PCAvVHlwZSAvQ2F0YWxvZw0KICAgICAvUGFnZXM
gMiAwIFINCiAgPj4NCmVuZG9iag0KDQoyIDAgb2JqDQogIDw8IC9UeXBlIC9QYWdlcw0KICAgICAvS2lkcyBb
MyAwIFJdDQogICAgIC9Db3VudCAxDQogICAgIC9NZWRpYUJveCBbMCAwIDMwMCAxNDRdDQogID4+DQ
plbmRvYmoNCg0KMyAwIG9iag0KICA8PCAgL1R5cGUgL1BhZ2UNCiAgICAgIC9QYXJlbnQgMiAwIFINCiAgIC
AgIC9SZXNvdXJjZXMNCiAgICAgICA8PCAvRm9udA0KICAgICAgICAgICA8PCAvRjENCiAgICAgICAgICAgICAgID
w8IC9UeXBlIC9Gb250DQogICAgICAgICAgICAgICAgICAvU3VidHlwZSAvVHlwZTENCiAgICAgICAgICAgICAgIC
AgIC9CYXNlRm9udCAvVGltZXMtUm9tYW4NCiAgICAgICAgICAgICAgID4+DQogICAgICAgICAgID4+DQogICA
gICAgPj4NCiAgICAgIC9Db250ZW50cyA0IDAgUg0KICA+Pg0KZW5kb2JqDQoNCjQgMCBvYmoNCiAgPDwgL
0xlbmd0aCA1NSA+Pg0Kc3RyZWFtDQogIEJUDQogICAgL0YxIDE4IFRmDQogICAgMCAwIFRkDQogICAgKEhl
bGxvIFdvcmxkKSBUag0KICBFVA0KZW5kc3RyZWFtDQplbmRvYmoNCg0KeHJlZg0KMCA1DQowMDAwMD
AwMDAwIDY1NTM1IGYgDQowMDAwMDAwMDE4IDAwMDAwIG4gDQowMDAwMDAwMDc3IDAwMDA
wIG4gDQowMDAwMDAwMTc4IDAwMDAwIG4gDQowMDAwMDAwNDU3IDAwMDAwIG4gDQp0cmFpb
GVyDQogIDw8ICAvUm9vdCAxIDAgUg0KICAgICAgL1NpemUgNQ0KICA+Pg0Kc3RhcnR4cmVmDQo1NjUNC
iUlRU9G';

function atomMain() {
var recipients = [
{ id: 1
, order: 1
, name: 'A Person'
, email: 'person31415@mailinator.com'
},
{ id: 2
, order: 2
, name: 'Another Person'
, email: 'person51413@mailinator.com'
}];
var files = [
{ name: 'myDocument.pdf'
, content: minimalPdf
}];
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

dummyRecipients.js

function dummyRecipientsMain() {
var dummyRecipients = [
{ id: 1
, order: 1
, name: 'An Approver'
, email: 'a.approver@mailinator.com'
},
{ id: 10
, order: 3
, name: 'International Person'
, email: 'i.person@mailinator.com'
}];
var nsRecipients = docusignGetRecipients(docusignContext, 2, 2);
var recipients = dummyRecipients.concat(nsRecipients);
var files = docusignGetFiles(docusignContext);
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

Advance Scripts for filtering Documents


Ex: A NetSuite Record has the following attached documents:
1. Contact Part 1.pdf
2. Contact Part 2.pdf
3. Partnership Agreement.doc
4. NDA.docx
5. Sales_Internal_info.xlsx

Example #1 Exact Match


Only include Partnership Agreement.doc in the DocuSign Envelope

function customSendMain() {
var searches = [
{ keyword: 'Partnership Agreement.doc'
, type: 'exact' }
];
var recipients = docusignGetRecipients(docusignContext);
var files = docusignGetFiles(docusignContext, searches);
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

Example #2 Phrase Match


Only include Contact Part 1.pdf and Contact Part 2.pdf in the DocuSign Envelope

function customSendMain() {
var searches = [
{ keyword: 'Contact Part'
, type: 'phrase' }
];
var recipients = docusignGetRecipients(docusignContext);
var files = docusignGetFiles(docusignContext, searches);
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

Example #3 Broad Match


Only include NDA.docx and Sales_Internal_info.xlsx in the DocuSign Envelope

function customSendMain() {
var searches = [
{ keyword: '.docx .xlsx'
, type: 'broad' }
];
var recipients = docusignGetRecipients(docusignContext);
var files = docusignGetFiles(docusignContext, searches);
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

Example #4 Using Multiple Match Types


Include all documents except Sales_Internal_info.xlsx in the DocuSign Envelope

function customSendMain() {
var searches = [
{ keyword: 'Partnership Agreement.doc'
, type: 'exact' },
{ keyword: 'Contact Part'
, type: 'phrase' },
{ keyword: '.docx'
, type: 'broad' }
];
var recipients = docusignGetRecipients(docusignContext);
var files = docusignGetFiles(docusignContext, searches);
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

Example #5 No document
Ignore all the attached documents. Create an empty DocuSign envelope.

function customSendMain() {
var searches = [
{ keyword: 'NO_DOCUMENT'
, type: 'exact' }
];
var recipients = docusignGetRecipients(docusignContext);
var files = docusignGetFiles(docusignContext, searches);
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

Advance Scripts for Sending

Example #1 Sending with DocuSign Template

function customSendMain() {
var recipients = docusignGetRecipients(docusignContext);
var files = [
{ type: 'template'
, id: '5C4B0AF2-9146-4A25-B8F1-0A77D4C9D3C7'
, signers: [
{ id: 1
, order: 1
, name: 'Approver One'
, email: 'netsuiteuserone@hotmail.com'
, role: 'Signer_1'},
{ id: 2
, order: 1
, name: 'Approver Two'
, email: 'netsuiteusertwo@hotmail.com'
, role: 'Signer_2'}
]}
];
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

Example #2 Sending with a specific attached document(using Exact search type)

Function customSendMain() {
var recipients = docusignGetRecipients(docusignContext);
var files = [
{ type: 'attachment'
, searches: [{ keyword: 'Partnership Agreement.doc', type: 'exact'}] }
]}
];
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

Example #3 Sending with DocuSign Template and attached documents

var minimalPdf =
'JVBERi0xLjENCiXCpcKxw6sNCg0KMSAwIG9iag0KICA8PCAvVHlwZSAvQ2F0YWxvZw0KICAgICAvUGFnZXM
gMiAwIFINCiAgPj4NCmVuZG9iag0KDQoyIDAgb2JqDQogIDw8IC9UeXBlIC9QYWdlcw0KICAgICAvS2lkcyBb
MyAwIFJdDQogICAgIC9Db3VudCAxDQogICAgIC9NZWRpYUJveCBbMCAwIDMwMCAxNDRdDQogID4+DQ
plbmRvYmoNCg0KMyAwIG9iag0KICA8PCAgL1R5cGUgL1BhZ2UNCiAgICAgIC9QYXJlbnQgMiAwIFINCiAgIC
AgIC9SZXNvdXJjZXMNCiAgICAgICA8PCAvRm9udA0KICAgICAgICAgICA8PCAvRjENCiAgICAgICAgICAgICAgID
w8IC9UeXBlIC9Gb250DQogICAgICAgICAgICAgICAgICAvU3VidHlwZSAvVHlwZTENCiAgICAgICAgICAgICAgIC
AgIC9CYXNlRm9udCAvVGltZXMtUm9tYW4NCiAgICAgICAgICAgICAgID4+DQogICAgICAgICAgID4+DQogICA
gICAgPj4NCiAgICAgIC9Db250ZW50cyA0IDAgUg0KICA+Pg0KZW5kb2JqDQoNCjQgMCBvYmoNCiAgPDwgL
0xlbmd0aCA1NSA+Pg0Kc3RyZWFtDQogIEJUDQogICAgL0YxIDE4IFRmDQogICAgMCAwIFRkDQogICAgKEhl
bGxvIFdvcmxkKSBUag0KICBFVA0KZW5kc3RyZWFtDQplbmRvYmoNCg0KeHJlZg0KMCA1DQowMDAwMD
AwMDAwIDY1NTM1IGYgDQowMDAwMDAwMDE4IDAwMDAwIG4gDQowMDAwMDAwMDc3IDAwMDA
wIG4gDQowMDAwMDAwMTc4IDAwMDAwIG4gDQowMDAwMDAwNDU3IDAwMDAwIG4gDQp0cmFpb
GVyDQogIDw8ICAvUm9vdCAxIDAgUg0KICAgICAgL1NpemUgNQ0KICA+Pg0Kc3RhcnR4cmVmDQo1NjUNC
iUlRU9G';

function customSendMain() {
var recipients = docusignGetRecipients(docusignContext);
var files = [
{ type: 'template'
, id: '5C4B0AF2-9146-4A25-B8F1-0A77D4C9D3C7'
, signers: [
{ id: 1
, order: 1
, name: 'Approver One'
, email: 'netsuiteuserone@hotmail.com'
, role: 'Signer_1'},
{ id: 2
, order: 1
, name: 'Approver Two'
, email: 'netsuiteusertwo@hotmail.com'
, role: 'Signer_2'}
] },
{ name: ' minimalPdf.pdf'
, content: minimalPdf },
{ type: 'attachment'
, searches: [{ keyword: 'Partnership Agreement.doc', type: 'exact'}] },
{ type: 'template'
, id: '039C2D21-1D2D-49A6-A09E-9CDAC196A234' }
];
return docusignPopulateEnvelope(docusignContext, recipients, files);
}

Advance Scripts for Signing

Example #1 Signing with a specific attached document

function customSignMain() {
var files = [
{ type: 'attachment'
, searches: [ { type: 'exact', keyword: 'Partnership Agreement.doc'} ]}
];
return docusignSignEnvelope(docusignContext, files);
}

Example #2 Signing with multiple DocuSign templates

function customSignMain() {
var files = [
{ type: 'template'
, id: '4DE59157-2650-43D6-83F7-8A03B762EC97'
, role: 'Signer_1'},
{ type: 'template'
, id: '501E1E3E-C925-4D2E-BEDB-C0787CAD7060'
, role: 'Signer_1'}
];
return docusignSignEnvelope(docusignContext, files);
}

Example #3 Signing with DS Template and attached document

function customSignMain() {
var files = [
{ type: 'template'
, id: '4DE59157-2650-43D6-83F7-8A03B762EC97'
, role: 'Signer_1'},
{ type: attachment
, searches: [ { type: 'exact', keyword: 'Partnership Agreement.doc'} ]}
];
return docusignSignEnvelope(docusignContext, files);
}

Você também pode gostar