Some fields must be hidden from different records for data confidentiality or security. In this article, we will be providing you with a sample script on how to hide a field if the user is not the owner of the task:
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(["N/runtime","N/error"],
(runtime, error) => {
/**
* 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
*/
constbeforeLoad= (scriptContext) => {
log.debug(scriptContext)
varcurrentRec=scriptContext.newRecord;
varassignedTo=currentRec.getValue({
fieldId:"assigned"
});
log.debug("assigned",assignedTo)
if(assignedTo!==runtime.getCurrentUser()){
varerrorMessage=error.create({
message:"This task is not assigned to you.",
name:"INVALID_USER"
});
throwerrorMessage;
}
}
return {beforeLoad}
});
Need help on how to deploy a script record? Visit New To NetSuite | How to Deploy a Script Record.
Do you have any feedback? Let us know in the comments!