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

You need to use gs.eventQueueScheduled() method like I did in my previous message in order to fire a delayed event. Any code that needs to be executed with a delay, should go into a Script Action reacting to that event and not into the same business rule that triggers it.


Slava Savitsky
Giga Sage

Another possibility is to use methods of the ScheduleOnce class. Here is an example:


Call a ServiceNow script asynchronously with ScheduleOnce API-John Andersen



To get a better insight into how this API works, explore ScheduleOnce script include in your ServiceNow instance.