Restrict Items on SO based on classification

Jira code: AN-2 Task 5

Restricting the Items on SO based on the item’s classification. If the item is not under “Finished Goods” class, script will not allow the item line commit

Client Script

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */

/**
 * Script Description: This script is for Restrict Items on SO based on classification  
 */

/*******************************************************************************
 * * AN * *
 * **************************************************************************
 * Date:7/11/18 
 * Script name: AN CS SO Btn Action
 * Script id: customscript_an_cs_so_btn_action
 * Deployment id: customdeploy_an_cs_so_btn_action
 * Applied to: Sales order
 * 

 ******************************************************************************/


define(['N/currentRecord','N/record','N/url'],

function(currentRecord,record,url) {
    
    /**
     * Function to be executed after page is initialized.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
     *
     * @since 2015.2
     */
    function pageInit(scriptContext) {
    	try {
    		console.log("In");
			
		} catch (e) {
			console.log(e.name,e.message);
		}
    }
    
    
    /**
     * Validation function to be executed when sublist line is committed.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @param {string} scriptContext.sublistId - Sublist name
     *
     * @returns {boolean} Return true if sublist line is valid
     *
     * @since 2015.2
     */
    function validateLine(scriptContext) {
    	try {
    		console.log("validateLine");
    		 if(scriptContext.sublistId=='item'){
    			 console.log("validate item");
                 var itemClass = scriptContext.currentRecord.getCurrentSublistValue({
         	 		fieldId: "class",
         	 		sublistId: 'item'
         	 	 });
                 console.log("itemClass",itemClass);
                 
                 var clsRecordObj = record.load({ type: "classification", id: itemClass});
	             var parentcls=clsRecordObj.getText({
	       			 fieldId: 'parent'
	           	 });
	             console.log("parentcls",parentcls);
	             if( !( (parentcls.startsWith("Finished :")) || (parentcls=="Finished") || (itemClass=='25'))){
	            	 alert("Sorry, you have selected an item that is not a finished good. Please remove the item and try again.");
	            	 return false;
	             }
                 
	             return true;
                
             }
    		
			
		} catch (e) {
			console.log(e.name,e.message);
		}

    }

    

    return {
        pageInit: pageInit,
        validateLine: validateLine
    };
    
});

Leave a comment

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