Restrict a User Role to Only Edit a Record via SuiteScript

Sample code snippet.

const beforeLoad = (scriptContext) => {
 var type = scriptContext.type;
            var userObj = runtime.getCurrentUser();
            var ACCESS_ROLE = userObj.role;

            if (ACCESS_ROLE != 3 && type == 'create') {

            var errorMsg = 'Your role is not permitted to Add this type of Record. '+ '<br><br> Please click <a href="javascript:history.go(-1)">'+ 'here</a> to go back.'​​​​​​
            throw error.create({name: 'Action not allowed', message: errorMsg });
            }
}

Leave a comment

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