- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 03:10 AM
Hi there,
I have a multi row variable set having two variables. here is don't want users to select the same option twice below is the code I was trying but it is not working and throwing javascript error in you console.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 03:29 AM - edited 04-28-2025 03:43 AM
Hello @pk2184046 ,
Please use this onSubmit script on your Variable Set:
function onSubmit() {
var mrvs = g_service_catalog.parent.getValue("additional_responsibilities_and_security_roles");
if (!mrvs) return true;
var arr = JSON.parse(mrvs);
var res = g_form.getValue("responsibility_add");
var sec = g_form.getValue("security_role_add");
var duplicate = arr.some(row =>
row.responsibility_add === res &&
row.security_role_add === sec);
if (duplicate) {
g_form.addErrorMessage('Row with same values already present.');
return false;
}
}
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 04:09 AM
Hello @pk2184046 ,
Glad to hear that.
The issue was that, in order to access the parent form, you need to use
g_service_catalog.parent
instead of
parent.g_form
There are many old scripts floating around with the latter code, but that doesn't work in Service Portal / Employee Center.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 03:17 AM
Hi @pk2184046
Could you share the pic of your MRVS & it's configuration?
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 03:45 AM
Hi Siva,
Please see the attached screenshot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 03:29 AM - edited 04-28-2025 03:43 AM
Hello @pk2184046 ,
Please use this onSubmit script on your Variable Set:
function onSubmit() {
var mrvs = g_service_catalog.parent.getValue("additional_responsibilities_and_security_roles");
if (!mrvs) return true;
var arr = JSON.parse(mrvs);
var res = g_form.getValue("responsibility_add");
var sec = g_form.getValue("security_role_add");
var duplicate = arr.some(row =>
row.responsibility_add === res &&
row.security_role_add === sec);
if (duplicate) {
g_form.addErrorMessage('Row with same values already present.');
return false;
}
}
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 03:49 AM
Hi Robert ,
I have tried the above code it's throwing the error and not working