How to show related incidents count on problem list view?

Ujjwala1
Tera Contributor

Hello All,

I have created custom field with integer type on problem form, I want to show related incidents count on that field when user is checking on problem.list view, Is there any way I can achieve this ?

I tried with display business rule, but that is displaying count only when user is opening the problem form, not working on list view.

Any kind of help is greatly appreciated!

Regards,

Ujjwala

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,

Since we are talking here about Incident related to Problem, so it can be that Problem might have been created from Incident or may be you have added your Incident using Related List on a Problem record, Problem Field on Incident record will always be updated as shown below:

find_real_file.png

So what I would suggest here is write a After Update Business Rule on Incident Table itself and update the count in your custom field instead of doing a query how many incident are linked and then storing it.

BR:

Table: Incident

After Update

Condition of BR: Problem Changes

Script:

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

	// Add your code here.
	var count = 1;
	var gr = new GlideRecord('problem');
	gr.addQuery('sys_id',current.problem_id);
	gr.query();
	if(gr.next()){
		gr.u_linked_incident = gr.u_linked_incident + count; // Replace "u_linked_incident" with your Field Name in Problem Table
		gr.update();
	}

})(current, previous);

find_real_file.png

Result:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

8 REPLIES 8

I have tested it and works perfectly well in my PDI.

Can you share your Script here and also screenshot on which Table you have written this BR on?

Please make sure the Table will be Incident where you need to write this BR on.

Also please make sure you have followed exactly what I have mentioned above.

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

I have selected 'Incident' table only to run BR should I change field type?

find_real_file.png

 

Checked your script and looks good to me. In order to get you to a solution couple of things I would like you to validate here:

1) Can you confirm the Problem Field backend Name and Label present on Incident?

2) How are you testing it? You need to change the Problem Field present on Incident form to have this working or may be you can add a Incident using Related List present on Problem form?

Please validate the way as suggested above.

For existing ticket , it will be a one time activity and you can update it using a Background script as shared below:

Script:

var gr = new GlideRecord('problem');
gr.addEncodedQuery();
gr.query();
while(gr.next()){
var relatedIncident = getRelatedIncident(gr.sys_id);
gr.u_linked_incident = relatedIncident;
gr.update();
}

function getRelatedIncident(problemID){
var c;
var gr1 = new GlideAggregate('incident');
gr1.addAggregate('COUNT');
gr1.addQuery('problem_id',problemID);
gr1.query();
while(gr1.next()){
c = gr1.getAggregate('COUNT');
}
return c;
}

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Anil Lande
Kilo Patron

Ji,

Please check similar question was answered before.

https://community.servicenow.com/community?id=community_question&sys_id=6e536fdadb2fb050b5d6e6be1396... 

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande