
- 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
10-05-2017 08:24 AM
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.
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 06:01 AM
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.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/