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

Sourabh26
Giga Guru

Hi,

 

You need to go for On Demand Script Include in this case.

 

Create a On Demand Script Include (use the below link for reference)

https://developer.servicenow.com/dev.do#!/learn/learning-plans/quebec/new_to_servicenow/app_store_learnv2_scripting_quebec_on_demand_script_include

 

Right click on your field --> Configure Dictionary --> Default Value -> javascript:ScriptIncludeName();

 

Mark this as Helpful/Correct if Applicable.

 

Regards,

Sourabh

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

what type of field it is?

how are you populating it?

you can make that field as calculated type and it would show on list and form both

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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

Hi @shloke04 ,

I did same, still field is showing nothing I applied the filter as 'problem id changes and problem id is not empty' Could you please suggest any changes here ?

find_real_file.png