Schedule job runs daily based on the custom table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 12:56 AM
Hi All,
i have created the custom table 'u_exceptions' table in this table we have 'u_reevaluation_date' field so now the schedule job will run every day, where u_reevaluation_date is 7 days from today. When that happens, the Scheduled Job should make a copy of that exception to a new record, set its state to Draft, and send a notification to the Requestor (u_requestor) that the exception needs to be re-evaluated. That same Scheduled Job should look for exceptions where u_reevaluation_date is today and set the state of those to Expired.
Please help me out how we can achieve this through script.
I am new learner so help me out the script for this one.
Thanks in Advance
Sravani.P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 01:39 AM
Hi, the best way to learn would be to make an attempt to write the script yourself.
The worst that can happen is you will need to ask additional question from the forum and luckily there are many members here more than happy to help you develop your skills.
I would suggest that you start by reviewing the GlideRecord methods
https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server_legacy/c_GlideRecordAPI?navFilter=
And take a look at OOB scheduled jobs in a (free) personal Developer Instance.
if you don't have a Personal Developer Instance (PDI), you should register here and request one
https://developer.servicenow.com/dev.do#!/home
The developer portal also has some excellent training courses wand I would suggest you review these as soon as you can.
https://developer.servicenow.com/dev.do#!/learn/
Perhaps this is a good starting point
https://developer.servicenow.com/dev.do#!/learn/courses/sandiego#scripting-in-servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 02:37 AM
var gr = new GlideRecord('u_exceptions');
gr.query();
var nowTime = new GlideDateTime();
while(gr.next){
var recordTime = gr.u_reevaluation_date;
var diff = gs.dateDiff(recordTime,nowtime,true);
if(diff/3600>7*24){
//Found the record seven days ago
}
}
Through the above code, you can find the record of 7 days ago, and you can write part of the rest yourself. Then send out questions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 03:34 AM
what is that 3600 can you please explain?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 06:42 PM
gs.dateDiff(recordTime,nowtime,true);
This method return seconds
diff/(60*60) Get hours
You can also
diff/(60*60*24) Get days