Create a Script for Sending E-Documents
This script sample script shows how to send e-documents.
This script can also be found at Creating a Script for Sending E-Documents as part of the Electronic Invoicing Adminstrator Guide.
Note:
This sample script uses the define
function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require
function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript Debugger.
The following code is a sample script for sending e-documents.
/**
* @NApiVersion 2.x
* @NModuleScope Public
*/
define(["N/record"], function(record, error) {
return {
/**
* send - Sample implementation: This will copy the e-document content to the document's
Memo field
*
* @param {Object} plugInContext
* @param {String} plugInContext.scriptId
* @param {String} plugInContext.sendMethodId
* @param {String} plugInContext.eInvoiceContent
*
* @param {Object} plugInContext.customer
* @param {String} plugInContext.customer.id
* @param {String[]} plugInContext.customer.recipients
*
* @param {Object} plugInContext.transaction
* @param {String} plugInContext.transaction.id
* @param {String} plugInContext.transaction.number
* @param {String} plugInContext.transaction.poNum
*
* @param {Object} plugInContext.sender
* @param {String} plugInContext.sender.id
* @param {String} plugInContext.sender.name
* @param {String} plugInContext.sender.email
*
*
* @returns {Object} result
* @returns {Boolean} result.success: determines
* @returns {String} result.message: a failure message
*/
send: function(plugInContext) {
var result = {
success: true,
message: "Success"
};
try {
var rec = record.load({
type: record.Type.INVOICE,
id: plugInContext.transaction.id,
});
rec.setValue({
fieldId: "memo",
value: [
"Script ID: " + plugInContext.scriptId,
"Customer: " + plugInContext.customer.name,
"Transaction: " + plugInContext.transaction.number,
"Sender: " + plugInContext.sender.name,
"Recipients: " + plugInContext.customer.recipients.join("\n"),
"Content: " + plugInContext.eInvoiceContent].join("\n\n")
});
rec.save();
} catch (e) {
result.success = false;
result.message = "Failure";
}
return result;
}
};
});