How to show unique records in reference variable?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 02:05 AM
Hi,
I have a table with 5000 records and duplicate records by name. but I want show to only unique records by in reference variable. for that I'm using advance reference qualifier. But issue is its taking some time to load. please help to do this in better way.
Below is the script for reference that I'm using
var appList = [];
var arrayUtil = new ArrayUtil();
var app = new GlideRecord('u_applications');
app.query();
while(app.next())
{
appList.push(app.u_application_name.toString());
}
var ids = [];
var uniqueArr = [];
uniqueArr = arrayUtil.unique(appList);
for(var i=0; i<uniqueArr.length; i++){
var app1 = new GlideRecord('u_applications');
app1.addQuery('u_application_name', uniqueArr[i]);
app1.query();
if(app1.next())
{
ids.push(app1.sys_id.toString());
}
}
return 'sys_idIN'+ids.toString();
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 02:40 AM
Can you try the following code?
var appList = [];
var app = new GlideAggregate('u_applications');
app.groupBy('u_application_name')
app.query();
while(app.next())
{
appList.push(app.getValue('u_application_name'));
}
for(var name in appList) {
var app1 = new GlideRecord('u_applications');
app1.addQuery('u_application_name', appList[name]);
app1.query();
if(app1.next())
{
ids.push(app1.getUniqueValue());
}
}
gs.info('ids::::'+ids)
If I could help you with my response you can mark it as helpful and correct as it benefits future viewers
Thanks,
Sai Kumar B
Community Rising Star 2023 & 2022