- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 02:14 AM
Hi ,
I would like to trigger an event from scheduled job based on count if greater than 0.
The event triggers but the state always showing as error.
Here is my script.
var dt=gs.nowDateTime();
var lutil = new Missing_computers().getCount();
//gs.print(lutil);
var gr=new GlideRecord('u_ashleyfurniture_domain_computers');
gr.addEncodedQuery('u_cnIN' + lutil);
//gr.addEncodedQuery('operational_statusIN1,3,4');
gr.query();
var count=gr.getRowCount();
if(count>0){
gs.eventQueue('missing.ad.records.cmdb', gr, gs.getUserID());
}
while(gr.next())
{
var gr1=new GlideRecord('u_missing_cmdb_computers');
gr1.initialize();
//gr1.setWorkflow(false);
gr1.u_created_data=dt;
gr1.u_source=gr.u_source;
gr1.u_cn=gr.u_cn;
gr1.insert();
}
Thanks,
Jagarnath
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 03:04 AM
I realized later,The reason why the job is not getting processed is, it is not having any glide record queried to get the output result. I just applied some logic and the notification is triggering now.
Note: I have replaced my table with the sys_user and if i need to get any info from the other tables in the notification content, i will take the help of notification email script.
Here is my revised code.
var dt=gs.nowDateTime();
var lutil = new Missing_computers().getCount();
//gs.print(lutil);
var gr=new GlideRecord('u_ashleyfurniture_domain_computers');
gr.addEncodedQuery('u_cnIN' + lutil);
//gr.addEncodedQuery('operational_statusIN1,3,4');
gr.query();
var count=gr.getRowCount();
if(count>0){
var gr2= new GlideRecord('sys_user');
gr2.addQuery('sys_id', 'c1ec13d80f0a650000af0bcce1050ea0');
gr2.query();
if(gr2.next()){
gs.eventQueue('missing.ad.records.cmdb', gr2, gr2.sys_id, count);
}
}
while(gr.next())
{
var gr1=new GlideRecord('u_missing_cmdb_computers');
gr1.initialize();
//gr1.setWorkflow(false);
gr1.u_created_data=dt;
gr1.u_source=gr.u_source;
gr1.u_cn=gr.u_cn;
gr1.insert();
}
Thanks,
Jagarnath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 02:25 AM
I think while loop should be inside if loop.
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
Thanks,
Deepa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 02:28 AM
Jagarnath
Maybe the row 5 is the root of the issue, give a try with something like following :
var myVariable = 'u_cnIN' + lutil;
gr.addEncodedQuery('myVariable');
Note : public void addEncodedQuery(String query)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 02:43 AM
Jagarnath / ZA
var myVariable = 'u_cnIN' + lutil;
gr.addEncodedQuery(myVariable); --------------------- Without quotes...
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
Thanks,
Deepa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 03:04 AM
I realized later,The reason why the job is not getting processed is, it is not having any glide record queried to get the output result. I just applied some logic and the notification is triggering now.
Note: I have replaced my table with the sys_user and if i need to get any info from the other tables in the notification content, i will take the help of notification email script.
Here is my revised code.
var dt=gs.nowDateTime();
var lutil = new Missing_computers().getCount();
//gs.print(lutil);
var gr=new GlideRecord('u_ashleyfurniture_domain_computers');
gr.addEncodedQuery('u_cnIN' + lutil);
//gr.addEncodedQuery('operational_statusIN1,3,4');
gr.query();
var count=gr.getRowCount();
if(count>0){
var gr2= new GlideRecord('sys_user');
gr2.addQuery('sys_id', 'c1ec13d80f0a650000af0bcce1050ea0');
gr2.query();
if(gr2.next()){
gs.eventQueue('missing.ad.records.cmdb', gr2, gr2.sys_id, count);
}
}
while(gr.next())
{
var gr1=new GlideRecord('u_missing_cmdb_computers');
gr1.initialize();
//gr1.setWorkflow(false);
gr1.u_created_data=dt;
gr1.u_source=gr.u_source;
gr1.u_cn=gr.u_cn;
gr1.insert();
}
Thanks,
Jagarnath