How to set up periodic schedule jobs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2021 12:43 AM
Hi,
For example, 3 ECRb Change requests are rasied and waiting for aproval.
If there are 3 change requests and CRB recommendation field they have updated it in differennt intervals.
So can we schedule a Job which will run periodically like set a time line of 3 hours. So every 3 hours it will check for which ECRB Change requests that CRB Recommendation field got updated and it will club all the changes and we can send an email?
Is this possible?
Please suggest me how to acheive this?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2021 01:59 AM
Hi,
why not if your query is on change_request table only?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2021 02:12 AM
My query is on Change request table only Ankur.
Here im able to get only the below mentioned query.
type=emergency_crb^stateIN-22,-10^approvalINrequested,approved
But i need the field CRB Recommendation changes also.
So please help me how to get that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2021 02:54 AM
Hi,
you cannot test for changes using the schedule job script
Is CRB Recommendation field not on change_request table
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 06:41 AM
Hi Ankur,
I would like to set up a scheduled job to run in weekdays as per CET timezone starting from 18:00 PM CET and runs after a gap of 2 hours till 04 AM CET.
It means on weekdays this would run for 5 times in CET: 18:00 pm, 20:00 pm, 22:00 pm, 02:00 am, 04:00 am
Can you please let me know whether you have come across such setting or configuration in past or how do I set this up?
Quick response would be much appreciated!!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2021 02:15 AM
Hi,
Yes you can create a scheduled job to run every 3 hours and in that add script like this.
1. put right crb field name in the code in all places.
2. ensure the notification listen to your event
3. The content is passed as parameter 1 of the event which you can use in the notification.
var gdt = new GlideDateTime();
gdt.addSeconds(-10800);//less than 3 hours
var gr = new GlideRecord("change_request");
gr.addQuery("sys_updated_on",">=",gdt);
gr.addEncodedQuery("your_crb_recommendation_fieldISNOTEMPTY");
gr.query();
var content = "";
while(gr.next()) {
//check if the field CRB Recommendation actually got updated in last 3 hours or not.
var gr1 = new GlideRecord("sys_journal_field");
gr1.addQuery("sys_created_on",">=",gdt);
gr1.addEncodedQuery(element_id=""+gr.sys_id+"^element=your_crb_field_name");
gr1.orderBy("sys_created_on");
gr1.setLimit(1);
gr1.query();
if(gr1.next()) {
content = content+gr.number.toString()+": "+gr1.value.toString()+"\n";
}
}
//now trigger the event with the content
gs.eventQueue("your_event_name",gr,content,"");
Mark the comment as a correct answer and also helpful if this helps to solve the problem.