Extend E-Document Transaction Response Generation Using Extend E-Invoicing Plug-in
By implementing the extend e- invoicing plug-in, you can modify the generated XML file by adding new nodes or
adding and removing attributes from existing nodes.
Use this plug-in when a transaction response template requires custom outbound response content.
The following code sample shows an extend e- invoicing plug-in implementation:
/**
*@NApiVersion 2.x
*@NScriptType plugintypeimpl
*/
define(["N/log"], function (log) {
/**
* Modifies the Transaction Response content.
*
* @param {Object} params - Parameters for content modification.
* @param {Object} params.transactionRecord - Details of the transaction record (loaded via N/record)
* @param {string|number} params.transactionResponseRecId - Transaction Response Internal ID
* @param {string|number} params.userId - User internal ID (Current User or First Active Admin)
* @param {Object} params.transactionResponseData - Returned as part of CDS response
(customDataSources[0].data)
* @param {string} params.trContent - Transaction Response content
* @returns {Object} Result object indicating success or failure.
* @returns {boolean} result.success - Indicates whether the modification was successful.
* @returns {string} [result.content] - The modified Transaction Response content (present when
success is true).
* @returns {string} [result.trErrorMsg] - Error description displayed on Error Details Tab (present
when success is false).
*/
function extend(params) {
var result = {
success: false,
};
try {
var finalContent = "";
/**
* Implement logic to extend the Transaction Response content
*/
result.success = true;
result.content = finalContent; // Contains final XML
} catch (err) {
log.error("Plugin Error", err);
result.trErrorMsg = err.message; // Default message will be used if message is not provided
}
return result;
}
return {
extend: extend,
};
});