- 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-07-2023 06:35 AM
so does it mean every row of MRVS should have variable 2 populated in it?
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 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-07-2023 09:21 AM
script I shared above should also work fine.
Did you try that?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader