Script to change value in transaction field

Description

The following script will search and find invoices under given conditions. Then a field in each invoice is updated with a given value.

Sample Script

/**
 * @NApiVersion 2.x
 * @NScriptType MapReduceScript
 * @NModuleScope SameAccount
 */
//--------------------------------------------------------
//   Script to re-trigger failed payments , this script will set value true for a mentioned field 
//--------------------------------------------------------
/** Date created : 21/02/2019
 * 
 * REVISION HISTORY
 * 
 * Revision 1.0 ${21/02/2019} rj : created
 */
define(['N/search', 'N/record', 'SuiteScripts/Jobin and Jismi IT services LLP/ESW Maint File/errorLog.js'], function (search, record, errorLog) {

    function deleteMaint(scriptContext) {

        try {

            // Set retrigger to invoice to the custom field.

            record.submitFields({
                type: record.Type.INVOICE,
                id: scriptContext.key,
                values: {
                    custbody_adyen_payment_retrigger: true
                },
                options: {
                    enableSourcing: false,
                    ignoreMandatoryFields: true
                }
            });

        } catch (err) {
            log.debug("error@deleteMaint", err);
        }
    }

    return {

        getInputData: function (scriptContext) {
            return search.create({
                type: "invoice",
                filters:
                    [
                        ["type", "anyof", "CustInvc"],
                        "AND",
                        ["custbody_adyen_payment_retrigger", "is", "F"],
                        "AND",
                        ["mainline", "is", "T"],
                        "AND",
                        ["custbody_adyen_error_message", "isnotempty", ""],
                        "AND",
                        ["status", "anyof", "CustInvc:A"]
                        // ,
                        // "AND",
                        // ["internalidnumber", "equalto", "2544936"]
                    ],
                columns:
                    [
                        search.createColumn({ name: "internalid", label: "Internal ID" })
                    ]
            });


        },
        reduce: deleteMaint,
        summarize: function (summary) {
            try {
                log.debug('summary@summarize', summary);
            } catch (err) {
                log.debug('err@summarize', err);
            }

        }
    }

});

Leave a comment

Your email address will not be published. Required fields are marked *