Creating a Custom Plug-in Implementation for Extend E- Invoicing Plug-in

A custom Extend E- Invoicing plug-in implementation customizes and extends the structure of the generated e-documents. You can modify the already generated XML file and can add a new node to the XML file. You can also add or remove attributes to the existing node. This functionality is not restricted only to Avalara templates but can be used for non- Avalara templates as well. This functionality can also be extended to JSON files.

The following code is a sample custom plug-in implementation for the Extend E- Invoicing plug-in:

          /**
 *@NApiVersion 2.x
 *@NScriptType plugintypeimpl
 */
define(["N/log"], function (log) {
    /**
     * Modifies the e-document content.
     *
     * @param {Object} params - Parameters for document modification.
     * @param {Object} params.transactionRecord - Details of the transaction record (loaded via N/record)
     * @param {string|number} params.transactionId - Transaction Internal ID
     * @param {string|number} params.userId - User internal ID (Current User or First Active Admin)
     * @param {Object} params.transactionData - Returned as part of CDS response (customDataSources[0].data)
     * @param {string} params.eDocContent - E-document 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 e-document content (present when success is true).
     * @returns {string} [result.eiAuditTrailMsg] - Audit trail message or error description (present when success is false).
     *
     */
    function extend(params) {
        var result = {
            success: false,
        };
        try {
            var finalContent = "";
            /**
             * Implement logic to extend the e-document content
             */
            result.success = true;
            result.content = finalContent; // Contains final XML or JSON value
        } catch (err) {
            // Log any errors that occur during e-document content extension.
            log.error("Plugin Error", err);
            // Return an error response indicating failure.
            // eiAuditTrailMsg is displayed on the Transaction E-Document Audit Trail.
            result.eiAuditTrailMsg = err.message; // Default message will be used if message is not provided
        }
        return result;
    }

    return {
        extend: extend,
    };
}); 

        

General Notices