How to throw error in User Event script

define([‘N/runtime’, ‘N/error’], 

    /** 

* @param{search} search 

*/ 

    (runtime, error) => { 

        const ROLES = [ 1112 , 1046] 

        const LOCATION = [29] 

        const beforeLoad = (scriptContext) => { 

            if (scriptContext.type == scriptContext.UserEventType.EDIT) { 

                let curUser = runtime.getCurrentUser(); 

                let curRole = curUser.role 

                let curLoc  = curUser.location 

                if (!ROLES.includes(curRole) || !LOCATION.includes(curLoc)) { 

                    let myCustomError = error.create({ 

                        name: ‘NO_ACCESS_PERMISSION’, 

                        message: ‘You do not have permission to edit this record.’, 

                        notifyOff: false 

                    }); 

                    throw myCustomError.message 

                } 

            } 

        } 

        return { beforeLoad } 

    }); 

Leave a comment

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