- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 06:07 AM
Hello ServiceNow developers,
In a catalog item, we have a Multi-row variable set named as "MR variable" and in that we have 2 variables: "variable 1" and "variable 2". We have a requirement to restrict the submission of this form along with displaying an error message, if the "variable 2" field is empty even in one of the sets of data added by the users in this variable set. Could you help me with the client script to meet this requirement?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 06:38 AM
if yes then do this in onSubmit catalog client script on that catalog item
function onSubmit(){
var jsonString = g_form.getValue('mrvsVariableSetName'); // give the mrvs variable set name here
var isEmpty = false;
var parsedData = JSON.parse(jsonString);
for(var i=0;i<parsedData.length;i++){
if(parsedData[i].variable2 == ''){ // give here the variable 2 name
isEmpty = true;
break;
}
else{
isEmpty = false;
}
}
if(isEmpty){
alert("All the rows of MRVS should have variable 2 populated");
return false;
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 07:45 AM - edited 07-07-2023 07:53 AM
Hi @Ankur Bawiskar , i tried using your solution posted in this question Solved: Validation on Multi Row Variable Set - ServiceNow Community and it works. I just replaced the variable set name, variable name and changed other things. It prevents the submission and displays the error message as well, when the "variable 2" field is kept empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 03:53 AM - edited 07-10-2023 03:57 AM
Yes, i also tried the above script posted by you, it also works fine as expected. I have accepted that as solution as well in this article. Thank you so much for the help.
Regards,
Amogh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 10:20 AM
What if we wanted to prevent submission of the form based on a single variable? I tried some code, but it did not work.
function onSubmit() {
//Type appropriate comment here, and begin script below
var accomm = g_form.getValue('u_accommodation_type');
if (accomm == 'religious') {
g_form.addInfoMessage('Please click here to submit a religious accommodation request.');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 03:30 AM
Hi Ankur
Can we have this on onchange of a variable in MRVS, so that error message will be popped on the variable itself and how can we clear just that variable value, not the entire MRVS?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 05:16 PM
@Ankur Bawiskar The script you shared does not work in ServicePortal. Did it work for you in portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 10:16 PM
can you post a new question and tag me there with all the details as this thread is old?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader