Scenario:
On button click,a field value need to be validate.If value is not set in the field then error message need to be displayed.
And the further button action need to be prevented in Client script.
Solution:
Use ‘N/ui/message’ module
Code snippet:
function in client script called on button action:
// Defining the function called in User Event Script
function onclick_approveEmail() {
try {
var curRec = currentRecord.get();
var recordId = curRec['id'];
var fieldLookUp = search.lookupFields({
type: search.Type.ESTIMATE,
id: recordId,
columns: ['entity', 'custbody_jj_expct_delivery_date']
});
var EDD = fieldLookUp.custbody_jj_expct_delivery_date;
if(EDD=='' || EDD == null || EDD == undefined ) {
showErrorMessage('Enter Expected Delivery Date');
return;
}catch (err) {
log.error({title: "Error setting check box field value", details: err.message});
function showErrorMessage(msgText) {
let myMsg = msg.create({
title: "Quote Approval Failed",
message: msgText,
type: msg.Type.ERROR
});
myMsg.show({
duration: 5000
});
}