I ahve created a catalog in side catalog i have one variable to add application if i already add
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2025 11:43 PM
I have created a catalog in side catalog i have one variable to add application if i already add the application with a name it should not allow to application with same name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 12:36 AM
create onSubmit catalog client script which applies to your MRVS variable set
script like this, taken from this link and 1st line is updated
How to stop duplicates entering in MRVS based on MRVS Variables(Applies Catalog item/ServicePortal)
function onSubmit() {
var multiRow = JSON.parse(g_service_catalog.parent.g_form.getValue("your_variable_set_here")); //This is the multirow that has already been submitted
var obj = {
'test1': g_form.getValue('test1'), //replace test1 with your variable1
'test2': g_form.getValue('test2'), //replace test1 with your variable2
'test3': g_form.getValue('test3'), //replace test1 with your variable3
'test4': g_form.getValue('test4'), //replace test1 with your variable4
};
if(multiRow) { //No need to run this if we don't have any values yet.
var result = multiRow.filter(function(item) {
//Replace below (test1 etc) with your appropriate variable names!
return (item.test1 == obj.test1 && item.test2 == obj.test2 && item.test3 == obj.test3 && item.test4 == obj.test4);
});
if(result.length > 0) {
g_form.addErrorMessage('You have entered the same twice');
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
‎05-05-2025 12:48 AM
I have only One variable which name is application name i need to prevent while adding the name it should not get added twice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 12:43 AM
Hi @AaravOjha
You can either mark Unique checkbox as true for Application Name variable. OR
You can have on submit client script to validate if MRVS has any duplicate value, here is sample script for you:
var mrvs = g_form.getValue('your_mrvs_variable_name');
var parsed = JSON.parse(mrvs);
var values = [];
for (var i = 0; i < parsed.length; i++) {
var val = parsed[i].application;
if (values.indexOf(val) !== -1) {
alert('Duplicate values are not allowed in the MRVS field.');
return false;
}
values.push(val);
}
return true;
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 12:57 AM
This is even not allow to submit getting this error
Error MessageonSubmit script error: SyntaxError: Unexpected token 'm', "mm" is not valid JSON:
function () { [native code] }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 03:27 AM
It worked for me with Unique checkbox on Select Box variable
It worked for me for Single Iine text variable as well
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