Passing Object as Parameters In User event script

We can pass array object as parameters from user event script to client script.

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
/*******************************************************************
 *   UseEventScript
 ****************************************************************
 *
 * Date: 22/06/2022
 *
 * Author: Jobin and Jismi IT Services LLP
 *
 * REVISION HISTORY
 *
 * Revision 1.0
 *
 * Description: Script to create custom button in the item record of type kit and service.
 *
 * Revision 2.0
 *
 ***************************************************************/

define(['./JJ CM Button Creation RMCE18', 'N/record'],

    (modelresolver, record) => {
        /**
         * @description function to create button in the record
         * @param {Object} scriptContext
         */
        const beforeLoad = (scriptContext) => {
            try {
                if (scriptContext.type === scriptContext.UserEventType.VIEW) {
                    var form = scriptContext.form;
                    var type = scriptContext.newRecord.type;
                    if (type == 'kititem' || 'serviceitem') {

                        var recObj = scriptContext.newRecord;
                        var itemObj = {}
                        var itemid = recObj.getValue({fieldId: 'itemid'});
                        var id = recObj.getValue({fieldId: 'internalid'});
                        var itemName = recObj.getValue({fieldId: 'itemid'});
                        var productName1 = recObj.getValue({fieldId: 'description'});
                        var productGR = recObj.getValue({fieldId: 'department'});
                        var saleRate = recObj.getValue({fieldId:                  'custitem_appf_kit_cost'});
                        var status = recObj.getValue({fieldId: 'isinactive'})
                        itemObj.itemName = itemName;
                        itemObj.productName1 = productName1;
                        itemObj.productGR = productGR;
                        itemObj.saleRate = saleRate;
                        itemObj.status = status;
                        itemObj.type = type;
                        var newItem = JSON.stringify(itemObj);
                        if (status == false) {
                            modelresolver.createCustomButton(form, 'Send Item Details to POS', 'sendItemDetailstoPOS(' + newItem + ')')
                        }
                    }
                }
            } catch (e) {
                log.debug("error @ before load", e)

            }
        }
        return {beforeLoad}
    });

Leave a comment

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