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:43 PM
What you have is good start, just a few minor changes:
var inc = new GlideRecord('incident');
inc.addQuery('cmdb_ci', current.cmdb_ci);
inc.addQuery('incident');
gs.log('cmdb: ' + current.cmdb_ci.name);
inc.query();
if (inc.next()){
var numb = inc.getRowCount();
gs.log('count is: ' + numb);
if (numb >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:43 PM
Please try this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ci = current.getValue('cmdb_ci');
var inc=new GlideRecord('incident');
inc.addQuery('cmdb_ci', ci);
inc.addActiveQuery();
inc.query();
if (inc.next())
if (inc.getRowCount() >= 5)
{
var pbmtbl=new GlideRecord('problem');
pbmtbl.initialize();
pbmtbl.short_description=current.short_description;
pbmtbl.state='Open';
pbmtbl.insert();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 09:38 PM
Hi Ramakrishna,
Create Business rule on After update and you can pass condition
Condition : configuration item changes and problem isEmpty
Code:
var inc = new GlideRecord("incident");
inc.addQuery("cmdb_ci",current.cmdb_ci);
inc.query();
if(inc.getRowCount() > 5){
var prb = new GlideRecord('problem');
prb.initialize();
prb.short_description="Creating "+current.cmdb_ci.getDisplayValue();
prb.insert();
}
Thanks
Pavan Dodla
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
01-09-2022 10:02 AM
- if more than 5 incidents got created and active but not resolved state got created on the same configuration item then after creating 5th incident the remaining 4 incidents should be made a child of 5th incident
any one pls support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2024 06:19 AM - edited 09-04-2024 06:24 AM
Hi @ramkrish ,
Have you figured out the solution? Could you please share the same , we have a similar requirement and I dont see any workable solutions yet,
Thank you!