How to prevent duplicate data entries in Multi row variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2020 08:01 AM
Hi,
I have created a multi-row variable set for one of the catalog items. I want to prevent user from entering duplicate entries.
I referred to https://community.servicenow.com/community?id=community_question&sys_id=8557faef1b8a5050305fea89bd4b...
However it doesn't seem to be doing anything for me. Attached is the image of the variable set i am using.
Below is the script i modified for the same taking reference of the provided script.
Any help would be really appreciated.
function onSubmit() {
//Type appropriate comment here, and begin script below
var value = g_form.getValue('box_details_for_pick_up');
var arr = JSON.parse(value);
var totalLength = arr.length;
var arr2 = [];
for(var i=0;i<arr.length;i++){
if(!searchExisting(arr[i].barcode,arr2)){
arr2.push(arr[i]);
}
}
var finalObjLength = arr2.length;
if(finalObjLength != totalLength){
alert('There are duplicates please remove those before submitting');
return false;
}
}
function searchExisting(barcode,newArray){
for(var i=0;i<newArray.length;i++){
if(newArray[i].barcode == barcode){
return true;
}
}
return false;
}
Regards,
Surabhi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 12:15 PM
Seems parent.g_form doesn't work in a portal. I'll look into it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2022 03:44 AM
is it possible to check all variables present in MRVS for duplicate instead of single variable?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2020 09:58 PM
Please check the Below Thread
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat