Fetch All incident number of given user

Sagar_pawar
Tera Contributor

Hello All,

I want to fetch all incident numbers of the same caller.

For example, suppose the caller is Abel tutor then print all incident numbers related to Abel tuter.

Thank You.

5 REPLIES 5

jaheerhattiwale
Mega Sage
Mega Sage

@Sagar_pawar Please try the below code

var inc = new GlideAggregate("incident");
inc.groupBy("caller_id");
inc.groupBy("number");
inc.query();

var incObj = {};
while(inc.next()){
    var caller = inc.caller_id.getDisplayValue();
    if(!caller){
        caller = "EMPTY";
    }
if(!incObj[caller]){
incObj[caller] = [];
}
incObj[caller].push(inc.number.toString());

}

gs.info(JSON.stringify(incObj));
 
Result:
jaheerhattiwale_0-1671550983887.png

 

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023