The CreatorCon Call for Content is officially open! Get started here.

Make the Business rule to wait for 2 minutes

Naveen Kumar J
Tera Expert

Hi,

As my instance host is getting populated after   1 minute of the record inserted I have used Async   after business rule   in order to the business rule to fire   once the condition is satisfied.

Conition : current.sys_created_by=='MIDServer'   && !current.u_instance_host.nil()

Table :cmdb_ci_db_mssql_instance

Script:

function onAfter(current, previous) {

    //This function will be automatically called when this rule is processed.

    var gr=new GlideRecord('sc_req_item');

  var item=gr.cat_item.name;

  gr.addQuery(item,'New MSFT SQL Database Instance Request');

  gr.addQuery('u_ci_name', current.name);

  gr.query();

  if(gr.next()){

  gr.variables.company=current.company;

  //gr.variables.server=current.u_instance_host;

  gr.update();

  }

  else {

  //gs.eventQueue("discover_router_ci", current, "","");

  }

}

This is not working.   Could anybody has an idea   to get this sorted out ?

Thanks.,

1 ACCEPTED SOLUTION

Unlike eventQueue() method, eventQueueScheduled() takes a fifth parameter (GlideDateTime object) that specifies when the event is to be fired. I guess something along these lines should work:



var when = new GlideDateTime();


var delay = new GlideTime();


delay.setValue("00:02:00");


when.add(delay);



gs.eventQueueScheduled("mssql_host_change", current, "", "", when);


View solution in original post

11 REPLIES 11

ahaz86
Mega Guru

I think you could use gs.sleep(120000) in the first line of your onAfter function


I used this one , but it is not working.


gs.sleep(12000);


function onAfter(current, previous) {


  gs.log("ritm" + current.u_instance_host);



    //This function will be automatically called when this rule is processed.


    var gr=new GlideRecord('sc_req_item');


  var item=gr.cat_item.name;


  gr.addQuery(item,'New MSFT SQL Database Instance Request');


  gr.addQuery('u_ci_name', current.name);


  gr.query();


  if(gr.next()){





  gr.variables.company=current.company;


  //gr.variables.server=current.u_instance_host;


  gr.update();



  }


  else {



  //gs.eventQueue("discover_router_ci", current, "","");



  }


}


use it inside of the onAfter function, not outside


Slava Savitsky
Giga Sage

Have your business rule fire a scheduled event using gs.eventQueueScheduled method (this would give you the possibility to control the delay) and set up a script action that will respond to the event and do whatever is required in your scenario.