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 02:02 AM
Please use below code:
var mvrsvalues= JSON.parse('service_details');
g_form.addInfoMessage(JSON.stringify(mvrsvalues)); // to print the JSON
//Below code is to access the JSON elements
for(var i=0; i<mvrsvalues.length;i++)
{
var service = mvrsvalues[i].service_question; // give here the variable name for proportion
var serviceAnswer =mvrsvalues[i].service_question_answer;
alert(serviceAnswer);
alert(service);
if (service != "" && serviceAnswer =='') {
g_form.alert('please fill Service Answer');
return false;
}
}
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 03:14 AM - edited 08-22-2023 09:57 PM
Hi Nayan,
still retuning undefined for
alert(serviceAnswer);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 02:07 AM
why not make those 2 variables as mandatory when MRVS form loads?
you can use catalog UI policy or catalog client script which applies on variable set and select the MRVS
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 03:05 AM
Hi Ankur,
Question variable will not be mandatory always, sometime there won't be any question for that service.
Applied UI policy on variable set but not working. Still request get submitted.