- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2024 05:30 AM
Hi Team,
I had a business requirement like, How to return list of latest 1 incident record based on caller.
Means, If Abel Tuter is having 8 incidents, I want the latest one incident.
Please help me with the approach.
Thanks in advance!
Regards,
Haseena
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2024 06:52 AM
Please refer below code:
var incidentList = [];
var incident1 = new GlideRecord('incident');
incident1.query();
while(incident1.next()){
var incident2 = new GlideRecord('incident');
incident2.addQuery('caller_id',incident1.caller_id);
incident2.orderByDesc('sys_created_on');
incident2.query();
if(incident2.next()){
incidentList.push(incident2.number.toString());
}
}
var uniqueIncidentList= new ArrayUtil().unique(incidentList);
gs.print(uniqueIncidentList);
Please let me know this code works for you or not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2024 05:54 AM
Hello @Haceena Shaik
Below code gives the desired output:
var incident = new GlideRecord('incident');
incident.addQuery('caller_id=62826bf03710200044e0bfc8bcbe5df1');//Caller is Abel Tuter
incident.orderByDesc('sys_created_on');
incident.query();
if(incident.next()){
gs.print(incident.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2024 06:02 AM - edited 02-10-2024 06:03 AM
Thanks for the quick response.
I want the list of atleast one incident based on all callers. But not based on one caller.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2024 06:52 AM
Please refer below code:
var incidentList = [];
var incident1 = new GlideRecord('incident');
incident1.query();
while(incident1.next()){
var incident2 = new GlideRecord('incident');
incident2.addQuery('caller_id',incident1.caller_id);
incident2.orderByDesc('sys_created_on');
incident2.query();
if(incident2.next()){
incidentList.push(incident2.number.toString());
}
}
var uniqueIncidentList= new ArrayUtil().unique(incidentList);
gs.print(uniqueIncidentList);
Please let me know this code works for you or not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2024 06:47 AM
Hi,
Please try the below code -
var inc = new GlideAggregate('incident');
inc.groupBy('caller_id');
inc.query();
while(inc.next()) {
var caller = inc.getValue('caller_id');
var incidentCaller = new GlideRecord('incident');
incidentCaller.addQuery('caller_id', caller);
incidentCaller.orderByDesc('sys_created_on');
incidentCaller.query();
if(incidentCaller.next()) {
gs.print(incidentCaller.number);
}
}