Where to do a check for duplicate records on UI page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 10:30 AM
Hi all,
I have created UI page with below code. The question is where and how to do a check for duplicates before creating the records in the "cmdb_rel_ci" table. I guess this should be through glide record. If duplicates are found I also want to display a message on below form that duplicates are found and the record/s cannot be created.
Client script:
function validate() {
nameCiValue = nameCi.value;
nameRelValue = nameRel.value;
namechildCis = childCis.value;
if (namechildCis == '') {
alert("Please choose child CI");
GlideDialogWindow.get().destroy();
return true;
} else if (nameCiValue == '') {
alert('Please fill in Parent field');
return false;
} else if (nameRelValue == '') {
alert('Please fill in Type of Relationship field');
return false;
} else {
var redirectURL = top.location.href;
top.window.location = redirectURL;
}
}
Processing script:
var array = childCis.split(','); for (var i = 0; i < array.length; i++) { var sysId = array[i]; var relType = new GlideRecord('cmdb_rel_ci'); relType.initialize(); relType.parent = nameCi; relType.type = nameRel; relType.child = sysId; relType.insert(); }
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 11:30 AM
Hello @Emanuil Hr ,
Yes, you are correct!
In the processing script, you can use glideRecord and using appropriate query you can check if the duplicate record is present or not ? If you not found duplicates then you can create new record as you wanted!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 06:33 AM
Ok but how exactly to built my script. Below piece of code is not working:
var array = childCis.split(',');
for (var i = 0; i < array.length; i++) {
var sysId = array[i];
var relType = new GlideRecord('cmdb_rel_ci');
relType.addQuery('parent','!=',nameCi);
relType.addQuery('type','!=',nameRel);
relType.addQuery('child','!=',sysId);
relType.addQuery();
if(relType.next()) {
relType.initialize();
relType.parent = nameCi;
relType.type = nameRel;
relType.child = sysId;
relType.insert();
}