Conditional script in scheduled job

raj10
Kilo Contributor

Hi team,

I just wanted to schedule a job with the script.

fetch all the number, comments , state, and state changed time from the incidents.

could you please help with the script. (conditional script and Run script)

Thanks for your help in advance,

 

raj

 

1 ACCEPTED SOLUTION

Hello Raj,

You still using my Old version of code.

Please update your code.,i already try to create a scheduled job on my personal instance and it is giving right solution of it.

Latest code is.

var grinc=new GlideRecord('incident');
grinc.query();
while(grinc.next())
{ 
   var grmet=new GlideRecord('metric_instance');
   grmet.addQuery('id',grinc.sys_id);//updated here
   grmet.addQuery('field','incident_state');
   grmet.orderByDesc('sys_created_on');
   grmet.setLimit(1);
   grmet.query();
   if(grmet.next());
   gs.print('Number-'+grinc.number+',State-'+grmet.value.toString()+',State_Change-'+grmet.sys_created_on);
  
} 

It is the updated code,please use this one.so yhat you will geT

INCIDENT NUMBER,Its current state,and the latest state change time.

Please keep posted for more help.I try the solution,it is working fine

Regards

Yash Agrawal

 

View solution in original post

51 REPLIES 51

Hello Raj,its strange b.coz i exactly copy and paste same code in my scheduled job at click on " Execute Now" button.

And in my case logs are getting created.

Will you please share the scrrenshot of error you are facing.

Reagrds

Yash Agrawal

Hello Raj,

Will you please provide the update,is that issue is resolved?

If yes,then please mark the answer as CORRECT,

IF NOT,please keep posted for more help.

Regards

Yash Agrawal

Hi Yash,

Still facing the issue

Hello Raj,

Please check the latest updated code from above comment.and just copy paste it in you scheduled job,you query will get resolved.

Please keep posted,if you want more help

Regards

Yash Agrawal

This is clearly a reporting requirement that can and should be solved by reporting.

Why are we encouraging the use of background script?

This is frankly an awful way to go about getting this data.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022