GET assignment groups history using REST API

i d
Kilo Contributor

Hi, 

I would like to get incident history using GET REST API. I've extracted a field like 'reassinged_count' gives me the count of the reassigned times for specific incident but is this possible to get the assignment group names?

Example:

INC12345 - reassinged count - 2 - Group A, Group B

Thanks

3 REPLIES 3

SumanthDosapati
Mega Sage
Mega Sage

Hey,

Try this code 

var audit = '';
var record_history = new GlideRecord('sys_history_set');
record_history.addQuery('id','46e2fee9a9fe19810049b49dee0daf58'); //sys id of record(incident sysid in this case)
record_history.query();
if(record_history.next())
{
audit = record_history.sys_id;
}
var groups = [];
var gr = new GlideRecord('sys_history_line');
gr.addQuery('set',audit);
gr.addQuery('field','assignment_group');  //which field data you need to fetch(assignment group in this case)
gr.orderBy('update_time');
gr.query();
while(gr.next())
{
    groups.push(gr.new_value.toString());
}
var grp = new GlideRecord('sys_user_group');
grp.addQuery('sys_id','IN',groups.join(','));
grp.query();
while(grp.next())
{
    gs.print(grp.name);
}

 

You can try that code in background scripts by giving any incident's sys id for testing.

 

Mark as correct and helpful if it worked.

Regards,

Sumanth

Just FYI- I haven't access to the API in the SNOW UI. Is this possible to apply conditions provided above to the sysparm_query?

 

Thanks

I would suggest like how you created a field for assignment count, you can create a new field for assignment values and store the values over there so it would be easy for you.

 

Mark as correct & Helpful if it worked for you.

Regards,
Sumanth