Why the record page got struck when we validate a field in fieldChanged function?

Here the sample code to check whether the opportunity name already exists, if it exist then it will show an error.

However, if you are not added return values, then it struck in the same field and page also not support to enter the next fields.

    function fieldChanged(scriptContext) {


    try {   

let currentRecord = scriptContext.currentRecord;             

if (scriptContext.fieldId === ‘title’) {                   

let opportunityName = currentRecord.getValue(‘title’);                   

//call the checkTitleExist function                 

let titleExists = checkTitleExists(opportunityName);                 

if (titleExists && checkForParameter(opportunityName)) {                     

alert (“The opportunity name is already exists. Please enter the different name”);                       

currentRecord.setValue({                         

fieldId: ‘title’,                         

value: ”                     

});                       

return false;                 

}                 

return true;               

}
} catch (error) {               

log.error(“error@fieldChanged”, error);         

}     

}

Leave a comment

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