- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 02:11 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 03:17 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 03:28 AM
Hi Mark,
thanks for your reply. I understood I have tried that also creating business rules.
but need a result at a time for all, instead of each time insert/update. that's why querying and scheduling the job.
else
if I want to schedule a business rule how can I do?
Raj

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 03:37 AM
Can you try the exact script I provided? Again, tested, works:
If wanting to get your own script working. I suggest you add things like .getValue() or .toString() because it does concern a scoped app.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2020 03:30 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2020 03:37 AM
Well that's because of your choosen logic. You are comparing different values to each other. Especially the last journey entry, that doesn't have to match the last update time etc..
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2020 04:40 AM
Hi Mark,
thanks for your help.
any idea to get the last state updated time of the incident? I have tried no correct output.
regards,
raj