Create a Custom Plug-in Implementation for E-Document Custom Data Source
The following sample shows how to add custom data sources to an e-document template.
For more information about custom plug-in implementations for custom data sources and this script, see Creating a Custom Plug-in Implementation for E-Document Custom Data Source.
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 SuiteScript Debugger.
The following code is a sample custom plug-in implementation for e-document custom data source.
* @NApiVersion 2.x
* @NScriptType plugintypeimpl
* @NModuleScope Public
*/
define(["N/render"], function(nsrender) {
/**
* inject - This function will provide the custom data source during the generation process
* @param {Object} params
* @param {String} params.transactionId
* @param {Object} params.transactionRecord
* @param {Number} params.userId
*
* @returns {Object} result
* @returns {‌render.DataSource} result.alias
* @returns {string} result.format
* @returns {Object | Document | string} result.data
* @returns {Object} result
* @returns {Boolean} result.success
* @returns {string} result.eiAuditTrailMsg
*/
function inject(params) {
var txnRecord = params.transactionRecord;
var txnId = params.transactionId;
var userId = params.userId
var customObj = {};
log.debug("Custom Object", customObj);
return {
customDataSources: [
{
format: nsrender.DataSource.OBJECT,
alias: "custom",
data: customObj
}
],
result: { //Optional
success:true, // Mandatory. Datatype: Boolean (true/false)
eiAuditTrailMsg:"Custom Data Source executed successfully." //Optional. Datatype: String
}
};
}
return {
inject: inject
};
});