
- 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 06:07 AM
Hi Slava,
I just followed your steps and dis the below the things.
1) Created an event called "mssql_host_change" and invoked this in a after business rule .
unction onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
if(!current.u_instance_host.nil()){
gs.eventQueueScheduled ("mssql_host_change", current, "", "");
}
}
2) Created a script action and invoked this event and in the condition and script i used the below statements.
Condition Script: current.sys_created_by=='MIDServer'
Script:
runsqliscovery();
function runsqldiscovery() {
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, "","");
}
}
But still it is not working. It seems i am doing something wrong somewhere.
Thanks
- 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
‎06-08-2017 11:31 AM
Hi Slava -
How I can pause Business rule to insert a records into a table after satisfying the condition.
Here is my code, but not working for me. It is satisfying the given condition but not waiting for 2 minutes, it is inserting as usual. Am I missing something?
var gr=new GlideRecord('Table');
//gr.addQuery("Condition");
gr.query();
if(gr.next()){
var when = new GlideDateTime();
var delay = new GlideTime();
delay.setValue("00:02:00");
when.add(delay);
gs.log("Delay");
Insert() // Insert record here after 2 minutes delay
}
else{
// Insert record here with no delay
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 12:12 AM
You cannot delay a business rule. What you can do, however, is use gs.eventQueueScheduled() method in your business rule to fire an event scheduled for a specific time in the future. In order to do this, feed a GlideDateTime object to the function as the fifth parameter (see my previous comment). You will also need to create a Script Action that would react to that event.
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-04-2017 05:38 AM
Hi
My code is mention below.. i need to execute current.deleteMultiple() 5mint delay in business rule how would have to do. please help me out
var when = new GlideDateTime();
var delay = new GlideTime();
gs.addInfoMessage(' current time1 '+gs.nowDateTime());
delay.setValue("00:08:00");
when.add(delay);
current.deleteMultiple();
gs.addInfoMessage(' current time2 '+gs.nowDateTime());