- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 11:27 AM
Is it possible to use a Catalog Client Script to verify that an entry is unique?
i.e. I have a select box (Yes/No) where there can only be one record with a "Yes" value. (There can be multiple records with a "No" value.)
Is it possible to check for this when they add the record but before they submit the form.
The select box is on a Variable Set, where multiple entries can be added.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 12:22 PM
Hi Donna,
For the best user experience, I would recommend doing this with an onChange Catalog Client Script that Applies to 'A Variable Set' (your MRVS) not 'A Catalog Item' when the select box variable changes. Your script will look something like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'Yes') {
var mrvs = g_service_catalog.parent.getValue('mrvs1'); //MRVS internal name
if (mrvs.length>2) { //native UI empty MRVS = '[]' which causes a JSON error
var obj = JSON.parse(mrvs);
for (var i = 0; i < obj.length; i++) {
if(obj[i].variable_name == newValue) { //replace with your variable name
g_form.clearValue('variable_name');
alert('Yes has already been selected in another row.');
}
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 12:22 PM
Hi Donna,
For the best user experience, I would recommend doing this with an onChange Catalog Client Script that Applies to 'A Variable Set' (your MRVS) not 'A Catalog Item' when the select box variable changes. Your script will look something like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'Yes') {
var mrvs = g_service_catalog.parent.getValue('mrvs1'); //MRVS internal name
if (mrvs.length>2) { //native UI empty MRVS = '[]' which causes a JSON error
var obj = JSON.parse(mrvs);
for (var i = 0; i < obj.length; i++) {
if(obj[i].variable_name == newValue) { //replace with your variable name
g_form.clearValue('variable_name');
alert('Yes has already been selected in another row.');
}
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 07:55 AM
Brad,
Thank You! I will give this a try and let you know how it works out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 08:47 AM
Brad,
That worked perfectly! Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 09:12 AM
You are welcome!