Print Assignment_group and its assigned incident numbers

Avinash5410
Tera Contributor

I want to print assignment group : incident numbers......... like Hardware : INC000111,INC0000233 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Avinash5410 Here is the script which can get you this data.

var glideIncident = new GlideAggregate('incident');
glideIncident.groupBy('assignment_group');
glideIncident.addAggregate('COUNT');
glideIncident.query();
while(glideIncident.next()){
    var assignment_group ={'id':glideIncident.getValue('assignment_group'),'name':glideIncident.getDisplayValue('assignment_group')};
    if(assignment_group.id!=''){
        var glideIncidentRec = new GlideRecord('incident');
        glideIncidentRec.addQuery('assignment_group',assignment_group.id);
        glideIncidentRec.query();
        var incidentNum ='';
        while(glideIncidentRec.next()){            
            incidentNum = incidentNum+glideIncidentRec.getValue('number')+',';
        }
        gs.print(assignment_group.name+':'+incidentNum);
    }
    
}

Here is the output.

Screenshot 2023-10-28 at 12.52.32 AM.png

Hope this helps.

View solution in original post

8 REPLIES 8

Sandeep Rajput
Tera Patron
Tera Patron

@Avinash5410 Here is the script which can get you this data.

var glideIncident = new GlideAggregate('incident');
glideIncident.groupBy('assignment_group');
glideIncident.addAggregate('COUNT');
glideIncident.query();
while(glideIncident.next()){
    var assignment_group ={'id':glideIncident.getValue('assignment_group'),'name':glideIncident.getDisplayValue('assignment_group')};
    if(assignment_group.id!=''){
        var glideIncidentRec = new GlideRecord('incident');
        glideIncidentRec.addQuery('assignment_group',assignment_group.id);
        glideIncidentRec.query();
        var incidentNum ='';
        while(glideIncidentRec.next()){            
            incidentNum = incidentNum+glideIncidentRec.getValue('number')+',';
        }
        gs.print(assignment_group.name+':'+incidentNum);
    }
    
}

Here is the output.

Screenshot 2023-10-28 at 12.52.32 AM.png

Hope this helps.

Could you pls explain line 6 what is id and name here. 

@Avinash5410 Do you need any further help on this topic? Please mark my answer correct if you have no further questions on this topic.

in the script what is the importance of the line

var incidentNum = " "; if it is for spare between the numbers we can give while printing , if i try with out this its only printing the first incident , pls explain this line and its importance