We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Prevent Submitting the form if Multi row variable set is empty

reddy8055
Tera Contributor

Hi,

I am populating multi row variable set based on requested for user info and want to prevent submitting the form whenever MRVS is empty. Tried mrvrs == '' like highlighted below in red but its not working.

 

function onSubmit() {
var today = new Date();
var mrvs = g_form.getValue('vta_training_details'); // internal name of your MRVS
alert(mrvs);
var obj = JSON.parse(mrvs);
for (var i = 0; i < obj.length; i++) {
var startDTe = obj[i].course_completed_date; // name of the MRVS variable
//alert(startDTe);
var startDateNum = getDateFromFormat(startDTe, g_user_date_format);
var coursedate = today - startDateNum;
//alert(coursedate);
var dayDifference = coursedate / (1000 * 60 * 60 * 24);
alert(dayDifference);
if ((dayDifference > 365) || (mrvs == '') || (mrvs == null)) {
g_form.addErrorMessage("Course Completed Date should not be more than 365 days");
return false;
}
}

 

Thanks,

11 REPLIES 11

reddy8055
Tera Contributor

@jaheerhattiwale 

I tried above solution, its not working

chahinazekhebiz
Tera Contributor

thank you so Much