Event is not getting processed

jagarnathn
Tera Expert

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

1 ACCEPTED SOLUTION

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


View solution in original post

6 REPLIES 6

Deepa Srivastav
Kilo Sage

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


zica
Giga Guru

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)



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


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