How to get number of incident records for a user in User form?

Jahnavi6
Kilo Expert

I would like to display the incidents count by particular user(i.e incidents caller_id=User's sys_id) on the User form. Can anyone help me how to achieve that?

 

9 REPLIES 9

Jaspal Singh
Mega Patron
Mega Patron

Hi Jahnavi,

 

You can simply create a report as below.

find_real_file.png

 

If you still will to have a field created & values populated you can have an Before Insert/Update business rule on incident table with below code.

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var getrelatedinci=new GlideRecord('incident');
	getrelatedinci.addQuery('caller_id',current.caller_id);
	getrelatedinci.query();
	while(getrelatedinci.next())
		{
	current.u_incidentcounts= parseInt(current.u_incidentcounts)+1; //replace incidentcounts with correct field name
		}

})(current, previous);

 

 

 

Hi,

Is there anyway that I can get the Incident number on the report you specified?

Thanks!

asifnoor
Kilo Patron

Hi,

1. For existing users you need a fix script to update the count of al incidents

2. Then write a BR and update whenever a new incident is created.

 

 

Jahnavi6
Kilo Expert

Hi,

I don't want to save this field value in User table. But, I would like the value be populated on User's list view. The field like "Default Value" can be used to write the javascript code there for this column? 

Note: I want the count be displayed on Users' form view.