Make variable mandatory on MVRS onsubmit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 01:30 AM
Hi Team,
I was trying below code to restriction submission of request before filling in mandatory variable not working, please suggest
function onSubmit() {
var values = g_form.getValue('service_details'); // give here mrvs variable name
var parser = JSON.parse(values);
for (var i = 0; i < parser.length; i++) {
var service = parser[i].service_question; // give here the variable name for proportion
var serviceAnswer =parser[i].service_question_answer;
alert(serviceAnswer);
alert(service);
if (service != "" && serviceAnswer =='') {
g_form.addErrorMessage('please fill Service Answer');
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 01:36 AM
Hello @Ash41 ,
Please try UI policy to make fields mandatory on form which is the standard practice.
You can also select the variables from MRVS in the ui Policy action.
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 01:42 AM
Hi Nayan,
I have already applied UI policy to make variable mandatory, still form is getting submitted if variable is empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 01:45 AM
Ok not sure why that is happening is * visible on field on required condition.
Going for the script can you please let me know are you getting values in the alerts which you have added.
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 01:49 AM
Hi Nayan,
Yes, I'm able to see * on variable. which is from Ui policy.
From script, when I put alerts for below getting undefined.
alert(serviceAnswer);