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

Hi Yash,

I have used the code whatever you have given above.

 

find_real_file.png

Hello Raj,

I will help you to solve this problem,

 please change the state of any incident.note that incident sys_id and go to metric_instance table,in that find ID column and try to paste the sys_id of incident you copied.

If records found open the latest created record.

And check the value is available in below fields or not.

1.Id-contains reference to incident record

2.value-contain updated state

3.field-should be incident state.

Also please  share scrrenshot of metric instance form.

Regard

Yash Agrawal

Hi Yash,

Thanks for your efforts.

 

is this you are asking?

find_real_file.png

Hello Raj,

No need to thanks dude,now i am exicted to know why it is not working.

I just executed that scheduled job,and the result is below.

find_real_file.png

If you dont have a problem can we have a quick meeting,

if yes then please provide your email id.

mine is yashagrawal3101@gmail.com 

Hello @raj,

Is that issue resolved,

If no,it is working in my system, lets have a quick meet

my email-yash.agrawal@dxsherpa.com

If resolved,

Please mark the Response as CORRECT and HELPFUL.it will also help other who are searching for same kind of answer.

Regards

Yash Agrawal