- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-12-2019 06:37 AM
how can show duplicate entries in computer table for particular field.
i want to show duplicate entries in report , please help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2019 12:05 AM
Hi Deepthi,
A script is the way to go on this one. I rigged this duplicate finder up. Feel free to alter it for your needs. I ran this as a background script in my instance with out issue (or results, we don't have any dupes!).
//highlight duplicate users
var arr = [];
var users = new GlideRecord('sys_user');
users.addActiveQuery();
users.query();
while(users.next()) {
arr.push(users.name.toString());
}
//sort array by name, duplicate name are placed next to each other in the array
arr.sort(function(a,b) {
return a<b ? 1 : a>b ? 1 : 0; });
//remove duplicates:
for(var j=0, len = arr.length, count=0, dupes=[]; j != len; j+=1) {
if ( arr[j] == arr[j+1] ) {//if the name is the same as the name in the next arr index
++count;
dupes.push(arr[j]);
}
}
//Output:
gs.log("There are " + count + " duplicate users detected.\nUsers found: ")
for (var k=0; k!=dupes.length;k+=1) {
gs.log(dupes[k]);
}
You can find below link that may help you to understand .
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks Deepthi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-12-2019 08:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-14-2019 11:25 PM
Hi Hardit Singh,
Thanks for your input.
i tried in following way as per your suggestion but when i RUN report 0 records where displaying, when i run same script in background script i am getting desired out put after printing. Please suggest.
please find my screen shot and script as below
Script Include:
function getDupes(){
var dupRecords = [];
var dpchk = new GlideAggregate('cmdb_ci_computer');
dpchk.groupBy('serial_number');
dpchk.addHaving('COUNT', '>', 1);
dpchk.query();
while(dpchk.next())
{
// gs.print(dpchk.serial_number);
}
return dupRecords;
}
Report:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2019 12:05 AM
Hi Deepthi,
A script is the way to go on this one. I rigged this duplicate finder up. Feel free to alter it for your needs. I ran this as a background script in my instance with out issue (or results, we don't have any dupes!).
//highlight duplicate users
var arr = [];
var users = new GlideRecord('sys_user');
users.addActiveQuery();
users.query();
while(users.next()) {
arr.push(users.name.toString());
}
//sort array by name, duplicate name are placed next to each other in the array
arr.sort(function(a,b) {
return a<b ? 1 : a>b ? 1 : 0; });
//remove duplicates:
for(var j=0, len = arr.length, count=0, dupes=[]; j != len; j+=1) {
if ( arr[j] == arr[j+1] ) {//if the name is the same as the name in the next arr index
++count;
dupes.push(arr[j]);
}
}
//Output:
gs.log("There are " + count + " duplicate users detected.\nUsers found: ")
for (var k=0; k!=dupes.length;k+=1) {
gs.log(dupes[k]);
}
You can find below link that may help you to understand .
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks Deepthi