- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2022 10:41 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2022 11:32 PM
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:
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);
Result:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2022 12:24 AM
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2022 12:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2022 12:49 AM
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
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2022 12:48 AM
Ji,
Please check similar question was answered before.
Thanks,
Anil Lande
Thanks
Anil Lande