Create problem when more than 5 incidents with same CI

ramkrish
Kilo Contributor

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();

}

10 REPLIES 10

Michael Fry1
Kilo Patron

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();


                                                                     


                                              }


Shishir Srivast
Mega Sage

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);


preddy
Kilo Guru

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


THIYAGESHWARAN
Tera Contributor
  1. 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

SanaPR
Giga Guru

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!