Custom Popup Notification For BO Items

Solution:

A popup notification will show while saving sales orders if any items are in backorder. The check box field called “In Active BO Popup Notification” will be created for the employee record. If the check box was checked then the back order popup notification will not show for the employee. 

The popup notification has following details for back-ordered items: 

  • Item code 
  • Qty Ordered 
  • Qty back ordered 
/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
/*******************************************************************************
 * Flowco Ltd t/a Waterworks
 ******************************************************************************
 * Date: 22 December 2022
 * Author: Jobin & Jismi IT Services LLP
 * Script Description: The client script is  for the button action and Back order Items Alert message.
 *
 ******************************************************************************/
define(['N/currentRecord', 'N/url','N/runtime', 'N/ui/dialog','N/record'],
    /**
     * @param{currentRecord} currentRecord
     * @param{url} url
     * @param{runtime} runtime
     * @param{dialog} dialog
     * @param{record} record
     */
    function(currentRecord, url,runtime,dialog,record) {
        /**
         * Validation function to be executed when record is saved.
         *
         * @param {Object} scriptContext
         * @param {Record} scriptContext.currentRecord - Current form record
         * @returns {boolean} Return true if record is valid
         * @since 2015.2
         */
        function saveRecord(scriptContext) {
            try{
                let currentUser = runtime.getCurrentUser().id;
                let employeeRecord = record.load({type:record.Type.EMPLOYEE,id:currentUser});
                let inactiveAlert = employeeRecord.getValue({fieldId:'custentity_jj_inactive_bo_notification'});
                let currentRecord = scriptContext.currentRecord;
                let itemLineCount = currentRecord.getLineCount({sublistId:'item'});
                let text = '';
                for (let i=0; i<itemLineCount; i++)
                {
                    //let BOQty = currentRecord.getSublistValue({sublistId:'item',fieldId:'backordered',line:i});
                    let availableQty = currentRecord.getSublistValue({sublistId:'item',fieldId:'quantityavailable',line:i});
                    let OrdQty = currentRecord.getSublistValue({sublistId:'item',fieldId:'quantity',line:i});
                    let BOQty = parseInt(OrdQty) - parseInt(availableQty);
                    if(BOQty > 0) {
                        let item = currentRecord.getSublistValue({sublistId:'item',fieldId:'item_display',line:i});
                        let itemArr = item.toString().split(':',2);
                        if(itemArr.length === 2) {
                            item =itemArr[1];
                        }else {
                            item =itemArr[0];
                        }
                        text += 'Item: "'+item+'" Ord.Qty: "'+OrdQty+'" BO Qty: "'+BOQty+'"\n';                    }
                }
                if(text && inactiveAlert === false) {
                    alert("The following Items are in the Back Ordered...\n\n"+text);
                }
                return true;
            }
            catch (e) {
                log.error({title: "error@saveRecord", details: e});
            }
        }
        return {
            saveRecord: saveRecord,

        };
    });

Leave a comment

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