Whenever the field location has the value “online sale” we will be triggering user event script
to set the mentioned fields as non-mandatory.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([],
() => {
/**
* 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) => {
try {
if (scriptContext.type === 'edit') {
var currentRecord = scriptContext.newRecord;
var locationField = currentRecord.getValue({
fieldId: 'location'
});
log.debug("locationField",locationField);
if(locationField === '13'){
currentRecord.getField('custbody6').isMandatory = false;
currentRecord.getField('custbody8').isMandatory = false;
currentRecord.getField('custbody_vehicle_description').isMandatory = false;
currentRecord.getField('custbody_vin').isMandatory = false;
currentRecord.getField('custbody_jj_servicetype').isMandatory= false; }
}
} catch (error) {
log.debug({ title: 'Catch Error', details: error });
}
}
/**
* Defines the function definition that is executed before record is submitted.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
* @since 2015.2
*/
return {beforeLoad}
});