Permission to edit Customer Deposit

const ROLES = [ 1112 , 1046]
const LOCATION = [29]
/**
* Defines the function definition that is executed before record is loaded.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord – New record
* @param {string} scriptContext.type – Trigger type; use values from the context.UserEventType enum
* @param {Form} scriptContext.form – Current form
* @param {ServletRequest} scriptContext.request – HTTP request information sent from the browser for a client action only.
* @since 2015.2
*/

    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 *