Hide sub customer sublist in a customer record.

Jira Code: TRS-22

Description:

In a customer record, if the fund field is not empty, then the sub customer sub-list is needed to be hidden. Otherwise, it needs to show in the customer record.

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
/** Script Description
 * .
 ******************************************************************************************************
  TRUST BRIDGE GLOBAL
 Hide the sub customer sublist if the fund number is not empty in customer record
 ******************************************************************************************************
 * Date: 21/06/2019
 * 
 * Author: Jobin & Jismi IT Services LLP 
 * 
 * Revision 1.0  ANJU 21/06/19
 *****************************************************************************************************/
define(['N/record', 'N/search', 'N/file', 'N/https', 'N/ui/serverWidget'],

    function(record, search, file, https, serverWidget) {

        var MODE = {
            'create': 'create',
            'edit': 'edit',
            'view': 'view'
        };

        //Common Try-Catch function
        function applyTryCatch(DATA_OBJ, NAME) {
            function tryCatch(myfunction, key) {
                return function() {
                    try {
                        return myfunction.apply(this, arguments);
                    } catch (e) {
                        log.error("error in " + key, e);
                        log.debug("error in " + key, e);
                        return false;
                    }
                };
            }
            for (var key in DATA_OBJ) {
                if (typeof DATA_OBJ[key] === "function") {
                    DATA_OBJ[key] = tryCatch(DATA_OBJ[key], NAME + "." + key);
                }
            }
        }
        var main = {



            beforeLoad: function(scriptContext) {

                var customerID = scriptContext.newRecord.id;

                if (MODE[scriptContext.type]) {

                    var currRec = record.load({
                        type: scriptContext.newRecord.type,
                        id: customerID
                    });


                    log.debug("scriptContext.newRecord", scriptContext.newRecord)

                    //if it is customer record
                    if (scriptContext.newRecord.type == 'customer') {



                        var fundNumber = currRec.getValue({
                            fieldId: 'cseg5'
                        });

                        if (fundNumber) {
                            log.debug('fundNumber', fundNumber);

                            //create an inline html field
                            var hideFld = scriptContext.form.addField({
                                id: 'custpage_hide_buttons',
                                label: 'not shown - hidden',
                                type: serverWidget.FieldType.INLINEHTML
                            });


                            //for every button you want to hide, modify the scr += line
                            var scr = "";
                            scr += 'jQuery("#subslnk").hide();';


                            //push the script into the field so that it fires and does its handy work
                            hideFld.defaultValue = "<script>jQuery(function($){require([], function(){" + scr + ";})})</script>";
                            log.debug('123test', 'test1234')
                        } else
                            log.debug('test1', 'test1');





                    }
                    currRec.save({ ignoreMandatoryFields: true });
                }

            } //EOF AFTER SUBMIT

        };

        applyTryCatch(main, "main");
        return main;
    });

Leave a comment

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