问题
I have a client Script for which I have to do validation using validatefield event. I have written the code . The condition is - If the date is other than Sunday, it should show a pop-up. But the pop-up is not showing. I have tried to achieve using the try and catch block, but it didn't work.Please look and suggest where I am going wrong
/**
*@NApiVersion 2.0
*@NScriptType ClientScript
*/
define(["N/currentRecord","N/search","N/runtime","N/record","N/ui/dialog"], function print(cr,search,runtime,record,dialog){
var exports = {};
function printMessage (context){
var startDate = context.currentRecord.getValue({
"fieldId": "custpage_start_date"
})
var endDate = context.currentRecord.getValue({
"fieldId": "custpage_end_date"
})
var date = new Date(startDate);
var day = date.getDay();
var options = {
title: 'Date entered',
message: 'Is Not correct'
};
console.log(day);
try{
if(day==0 && (startDate!='' || startDate!=undefined)){
return true;
}
console.log("Inside try block");
}
catch(e){
log.error({
title: e.name,
details: e.message
});
dialog.alert(options);
console.log("Inside catch block");
}
console.log("Outside")
}
exports.validateField = printMessage;
return exports;
})
来源:https://stackoverflow.com/questions/64301854/client-script-for-form-validation-not-working