Create problem when more than 5 incidents with same CI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 06:12 PM
Hi
I have coded below in after insert BR of incident. But it is not working, can you help here?
var inc=new GlideRecord('incident');
inc.addQuery('cmdb.ci', current.cmdb_ci);
gs.log('count is:' +current.cmdb_ci);
inc.query();
if (inc.next())
var count=inc.getRowCount();
gs.log('count is:' +count);
if (count >5)
{
var pbmtbl=new GlideRecord('problem')
pbmtbl.initialize();
pbmtbl.short_description=current.short_description;
pbmtbl.state='Open';
pbmtbl.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 06:40 PM
Hi Rama,
To achieve your requirement you need to create a after Insert Business rule on Incident (incident) table. Please find the script and screenshots below:
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideAggregate('incident');
inc.addAggregate('COUNT');
inc.addQuery('cmdb_ci', current.cmdb_ci);
inc.query();
var count = 0;
if (inc.next()) {
count = inc.getAggregate('COUNT');
if (count>5) {
var prb = new GlideRecord('problem');
prb.initialize();
prb.short_description="Creating this Problem as more than 5 Incidents are created on the Configuration item"+ current.cmdb_ci;
prb.state='Open';
prb.insert();
}
}
})(current, previous);
I hope this helps. Please mark correct/helpful based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 09:14 PM
Hi Alman and Rama,
Good suggestion that you posted. Nothing wrong with this, but I suspect if there is no control over the Problem table in creating the records your suggestion of this BR can lead to multiple problem records.
Example: If 6 incidents created(>5) for the same CI a problem gets created, if there is another incident i,.e, 7th, 8th or 9th etc... created for the same CI, the above logic creates another problem record with the short description of the 7th, 8th or 9th etc.. incident.
There a control need to implemented in the above BR code to achieve the creation of multiple problem records creation.
(Simply if a Problem is created at the creation of 6th incident for a CI, no problem should be created until the current problem is resolved)
If there is no issue with such multiple problems/Or if it is not an issue with your requirement please disregard my reply.
If you found this helpful please mark it as Correct/Helpful.
Thanks,
Saikiran Guduri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 09:29 PM
Hi Saikiran,
That's a very good point. Even I suspected the same, but eventually went forward with the logic as ramkrish used the condition as if(count>5) in the original question. I appreciate your suggestion Saikiran.
In this scenario, you have to change a slight in my Business rule script given in my last response. All Rama/you have to do is to change the if logic in line number 10 a bit. The logic, if(count=5) is enough to satisfy the condition and also this nullifies the unwanted scenario of multiple Problem creation.
Also one thing I would like to mention is, using GlideRecord and getRowCount() anybody can achieve the same requirement. But for performance reasons, GlideAggregate is always faster than GlideRecord.
I hope this helps. Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 09:59 PM
Hi ramkrish ,
Did you able to have a look at my last response?
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View