We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Total tickets logged today be team

MunafbhaiU
Kilo Contributor

How to get total tickets logged today by Team? This should also capture the tickets that were created by Team A but now assigned to Team B. 

1 REPLY 1

Mohammed8
Tera Sage

Hi @MunafbhaiU ,

I'm not sure you are asking for report or scripts but the use-case is pretty real and here is my take on it:

Using the background script helped verify two things. I used the Network team for testing, but the same logic works for any assignment group by using its sys_id.

  1. Which incidents were actually created today and are currently assigned to the Network team

  2. Whether the earliest assignment_group value in the audit history belonged to the Network team

Based on that, the script was able to correctly identify:

  • Tickets that were originally logged with the Network team

  • Tickets that were logged with the Network team but later reassigned to another team

Background Script:

 

var networkTeam = '287ebd7da9fe198100f92cc8d1d2154e'; // Network team sys_id
var base = gs.getProperty('glide.servlet.uri');

var currentNetworkIncidents = [];
var reassignedFromNetworkIncidents = [];
var sysIdList = [];
var seen = Object.create(null);

// Get all incidents created today
var inc = new GlideRecord('incident');
inc.addQuery('sys_created_on', '>=', gs.beginningOfToday());
inc.addQuery('sys_created_on', '<=', gs.endOfToday());
inc.query();

while (inc.next()) {

var sysId = inc.getUniqueValue();
var isCurrentNetwork = (inc.getValue('assignment_group') == networkTeam);

var everAssignedNetwork = false;

// Check if EVER assigned to network
var audit = new GlideRecord('sys_audit');
audit.addQuery('tablename', 'incident');
audit.addQuery('documentkey', sysId);
audit.addQuery('fieldname', 'assignment_group');
audit.addQuery('oldvalue', networkTeam);
audit.query();

if (audit.hasNext()) {
everAssignedNetwork = true;
}

// CURRENT
if (isCurrentNetwork && !seen[sysId]) {

seen[sysId] = true;
sysIdList.push(sysId);

currentNetworkIncidents.push([
inc.getValue('number'),
"Caller: " + inc.caller_id.getDisplayValue(),
inc.getValue('short_description') || ""
].join(" | "));
}
// REASSIGNED
else if (!isCurrentNetwork && everAssignedNetwork && !seen[sysId]) {

seen[sysId] = true;
sysIdList.push(sysId);

reassignedFromNetworkIncidents.push([
inc.getValue('number'),
"Caller: " + inc.caller_id.getDisplayValue(),
inc.getValue('short_description') || "",
"Now with: " + inc.assignment_group.getDisplayValue()
].join(" | "));
}
}


// PRINT CURRENT NETWORK INCIDENTS
gs.print("========== CURRENTLY ASSIGNED TO NETWORK ==========");
gs.print("Total: " + currentNetworkIncidents.length);
gs.print("---------------------------------------------------");

for (var i = 0; i < currentNetworkIncidents.length; i++) {
gs.print((i + 1) + ". " + currentNetworkIncidents[i]);
}


// PRINT REASSIGNED INCIDENTS
gs.print("\n========== REASSIGNED FROM NETWORK ==========");
gs.print("Total: " + reassignedFromNetworkIncidents.length);
gs.print("---------------------------------------------------");

for (var j = 0; j < reassignedFromNetworkIncidents.length; j++) {
gs.print((j + 1) + ". " + reassignedFromNetworkIncidents[j]);
}


// PRINT ONE COMBINED LIST LINK
if (sysIdList.length > 0) {
var listUrl = base + "incident_list.do?sysparm_query=sys_idIN" + sysIdList.join(",");
gs.print("\nCombined List View URL:");
gs.print(listUrl);
} else {
gs.print("\nNo incidents found for Network team today.");
}

 

Background Script Result:

 

Mohammed8_2-1764516311769.png

 

 Result Verification:

 

Mohammed8_0-1764516075799.png

 

Note:

In this use case we are checking just one day but the audit table is a heavy table, so this approach should only be used when the time window is small. 

 

If you find this answer useful, please mark it as solution accepted/helpful.

 

Thanks and Regards,

Mohammed Zakir