Update All Manufacturing Charges to the Current Purchase Price

The following sample updates the prices of all manufacturing charges on the transaction being edited to the current purchase price.

Note:

This script sample 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 2.x Global Objects.

          /**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define([
    'N/manufacturing/productionCharges',
    'N/runtime',
    'N/log'
], function(productionCharges, runtime, log) {

    async function afterSubmit(context) {
        if (context.type !== context.UserEventType.EDIT) {
            return;
        }

        var newRecord = context.newRecord;
        var transactionId = newRecord.id;

        // Check API requirements
        // Not necessary, but avoids exceptions thrown when calling API
        if (runtime.getCurrentUser().getPermission({name: "TRAN_BUILD"}) < runtime.Permission.EDIT) {
            log.error({title: 'Permission Error', details: 'Insufficient permissions for Assembly Build'});
            return;
        }

        if (runtime.isFeatureInEffect({feature: "MFGWORKINPROCESS"}) &&
            (runtime.getCurrentUser().getPermission({name:"TRAN_WOCOMPL"}) < runtime.Permission.EDIT ||
                runtime.getCurrentUser().getPermission({name:"TRAN_WOISSUE"}) < runtime.Permission.EDIT)) {
            log.error({
                title: 'Permission Error',
                details: 'Insufficient permissions for Work Order Completion or Work Order Issue'
            });
        }

        try {
            await productionCharges.updateAllChargesToItemPurchasePrice({
                transactionId: transactionId
            });

            log.audit({
                title: 'Success: updateAllChargesToItemPurchasePrice',
                details: 'All eligible charges updated for transaction ID: ' + transactionId
            });
        } catch (e) {
            log.error({
                title: 'Error in updateAllChargesToItemPurchasePrice',
                details: e.message + ' for transaction ID: ' + transactionId
            });
        }
    }

    return {
        afterSubmit: afterSubmit
    };
}); 

        

Related Topics

General Notices