How to Find Duplicate records

Pallavi65
Tera Contributor

Hi everyone,

 

I want to get all the duplicate names (same name for two or more records) for script includes. Like in an instance if there are 5403 script includes (active ones), then I want to know all the duplicate names of the script includes. Can someone help me here

 

Regards,

Pallavi

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello Pallavi,

Can you try executing below script in background script

I am pushing them into an array and printing the array 

var arr=[]
var gr = new GlideRecord('sys_script_include');
gr.query();
while(gr.next())
{
var dup = new GlideRecord('sys_script_include');
dup.addQuery('name',gr.name);
dup.addQuery('sys_id','!=',gr.sys_id);
dup.query();
while(dup.next())
{
if(arr.indexOf(dup.name.toString())==-1)
{
arr.push(dup.name.toString());
}
}
}
gs.print(arr);

Please mark my answer correct if it helps you

 

View solution in original post

3 REPLIES 3

Mohith Devatte
Tera Sage
Tera Sage

Hello Pallavi,

Can you try executing below script in background script

I am pushing them into an array and printing the array 

var arr=[]
var gr = new GlideRecord('sys_script_include');
gr.query();
while(gr.next())
{
var dup = new GlideRecord('sys_script_include');
dup.addQuery('name',gr.name);
dup.addQuery('sys_id','!=',gr.sys_id);
dup.query();
while(dup.next())
{
if(arr.indexOf(dup.name.toString())==-1)
{
arr.push(dup.name.toString());
}
}
}
gs.print(arr);

Please mark my answer correct if it helps you

 

Thank you Mohit. It's working

 

Have a nice time 🙂

 

 

Regards,

Pallavi

Maik Skoddow
Tera Patron
Tera Patron

Hi 

just having a look on the name of a Script Include is not helpful, as each Script Include has a namespace (global or custom scope) and only the combination of namespace and name of the Script Includes makes it unique.

Therefore checking the "API Name" is the better approach.

Kind Regards
Maik