
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2015 05:42 AM
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.,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2015 06:32 AM
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);
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2015 05:48 AM
I think you could use gs.sleep(120000) in the first line of your onAfter function

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2015 06:08 AM
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, "","");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2015 06:17 AM
use it inside of the onAfter function, not outside
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2015 05:55 AM
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.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/