i Need to exclude duplicates from database view and need to insert uique records in custom table.

Hareesha
Tera Contributor

I wrote a script to remove duplicated from database view and push into custom table.But it is pulling all records from database view to custom table.Appreciate your help.

var x=new GlideRecord("u_skills_updated");//database view
var y=new GlideRecord('u_skill_updated_last_180_days');//custom table
x.query();
var a,b,c,d,e,f,g,h;;
var count1=0
y.query();
var c1=0;
count1=y.getRowCount();
while(x.next())
{
a=x.getElement('grpmem_user.name');
b=x.getElement('grpmem_user.u_business');
c=x.getElement('grpmem_group.parent.name');
d=x.getElement('userskill_skill.name');
e=x.getElement('userskill_skill_level.name');
if(count1==0)//custom table is empty
{

y.setValue('u_user1',a);
y.setValue('u_business1',b);
y.setValue('u_parent',c);
y.setValue('u_skill1',d);
y.setValue('u_proficiency1',e);
y.insert();
count1=count1+1;
}
else //custom table is not empty
{
var y=new GlideRecord('u_skill_updated_last_180_days');//custom table
y.query();
while(y.next())
{
f=y.getElement('u_user1');
g=y.getElement('u_skill1');
h=y.getElement('u_parent');
if(a===f && c===h && d===g)
{
c1=1;
break;
}

}// Y while loop

if(c1!=1)
{
y.setValue('u_user1',a);
y.setValue('u_business1',b);
y.setValue('u_parent',c);
y.setValue('u_skill1',d);
y.setValue('u_proficiency1',e);
y.insert();
count1=count1+1;
c1=0;

}

}//else
}// X while loop

 

I need to get only 3 records

find_real_file.png

11 REPLIES 11

Hi Hareesha,

Since, my answer helped you to resolve your current question, I would suggest to mark appropriate answer as correct.

For your new query, please raise another question and let me know. I may need to investigate further on that part as I am not sure if we can write BR on database view table but someone will help you if you raise different question accordingly.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hi Hareesha,

You can write on delete BR on table from where data is merged in database view.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP