- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 01:21 AM
Hi ServiceNow Community,
I have a task, we have created a custom table called "Training Enquiry" which consists of various fields , one of which is "state" field. the requirement is that I need to write a scheduled job script such that all the training enquiry records which are in "New" state must be set to "Follow up" by the start of next week.
hoping to get some useful solution on this.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 01:47 AM - edited 01-17-2024 03:58 AM
Hi @Ubada Barmawar,
Set the Scheduled Job to weekly and put the day as Monday. Try the following script and correct any values if required. Also you can get a count of records updated in this:
var count = 0;
var gr = new GlideRecord('u_training_enquiry');
gr.addQuery('u_state', 'new');
gr.query();
while (gr.next()) {
gr.setValue('u_state', 'follow_up');
gr.update();
count++;
}
gs.log("Count of records updated: " + count);
If you found this reply useful, please mark it as solution/helpful.
Thanks and Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 01:32 AM
Hi,
Try below script:
(function executeRule() {
var trainingEnquiry = new GlideRecord('training_enquiry');
trainingEnquiry.addQuery('state', 'New');
trainingEnquiry.query();
var now = new GlideDateTime();
var nextWeekStart = new GlideDateTime();
nextWeekStart.addWeeks(1);
nextWeekStart.setDayOfWeek(1); // Set to Monday
while (trainingEnquiry.next()) {
// Update records with 'Follow up' state
trainingEnquiry.state = 'Follow up';
trainingEnquiry.update();
}
})();
Regards,
Shoheb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 01:47 AM - edited 01-17-2024 03:58 AM
Hi @Ubada Barmawar,
Set the Scheduled Job to weekly and put the day as Monday. Try the following script and correct any values if required. Also you can get a count of records updated in this:
var count = 0;
var gr = new GlideRecord('u_training_enquiry');
gr.addQuery('u_state', 'new');
gr.query();
while (gr.next()) {
gr.setValue('u_state', 'follow_up');
gr.update();
count++;
}
gs.log("Count of records updated: " + count);
If you found this reply useful, please mark it as solution/helpful.
Thanks and Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 02:12 AM
Please configure the scheduled job as below :
var tr = new GlideRecord('training_enquiry');
tr.addQuery('state', 'Your New State Value');
tr.query();
while(tr.next()) {
// Update records with 'Follow up' state
tr.state = 'Your Follow Up State Value';
tr.update();
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.