- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 04:03 AM
Hello Experts,
I need to create a report based on a scripted filter, based on reference field for one of the tables, I'm using below script-
Could anyone please guide me here, I want only single unique records for each of the u_local_party field the table, currently when we are applying group by using 'u_local_party' we are getting multiple records for single 'u_local_party' field value.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 05:30 AM - edited 10-26-2023 05:39 AM
Hi @Utkarsha ,
var SearchRec = Class.create();
SearchRec.prototype = {
initialize: function() {},
findUniqueRecords: function() {
var uniqueRecordSysIDs = [];
var previousLocalParty = '';
var vdrRecords = new GlideRecord('sn_vdr_tpro_checker');
vdrRecords.addEncodedQuery('u_draft!=cancelled');
vdrRecords.orderBy('u_local_party');
vdrRecords.query();
while (vdrRecords.next()) {
var localParty = vdrRecords.u_local_party.toString();
if (localParty !== previousLocalParty) {
uniqueRecordSysIDs.push(vdrRecords.sys_id.toString());
previousLocalParty = localParty;
}
}
return uniqueRecordSysIDs;
},
type: 'SearchRec'
};
Try above script.
Please mark it as solution proposed and helpful it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 04:26 AM
Hello @Utkarsha ,
You can use below method and remove duplicates
var au = new ArrayUtil();
var newChangeArr = au.unique(dupRecord);
type: 'SearchRec'
Your result will be stored in newChangeArr variable.
Thank you,
Omkar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 05:07 AM
Hi Omkar,
Thank you for replying.
I tried the code you shared, still not able to remove duplicates, i need to call this script in report
I am getting all the records from the table after running this filter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 05:30 AM - edited 10-26-2023 05:39 AM
Hi @Utkarsha ,
var SearchRec = Class.create();
SearchRec.prototype = {
initialize: function() {},
findUniqueRecords: function() {
var uniqueRecordSysIDs = [];
var previousLocalParty = '';
var vdrRecords = new GlideRecord('sn_vdr_tpro_checker');
vdrRecords.addEncodedQuery('u_draft!=cancelled');
vdrRecords.orderBy('u_local_party');
vdrRecords.query();
while (vdrRecords.next()) {
var localParty = vdrRecords.u_local_party.toString();
if (localParty !== previousLocalParty) {
uniqueRecordSysIDs.push(vdrRecords.sys_id.toString());
previousLocalParty = localParty;
}
}
return uniqueRecordSysIDs;
},
type: 'SearchRec'
};
Try above script.
Please mark it as solution proposed and helpful it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 10:16 AM