Automatic deactivation of Standard Change Template through Scheduled Jobs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2023 11:25 AM
What is required is that once the date in the expiration date field is reached, the Active field changes from true to false.
I have this but when I run it, it gives me all of them, including those with a higher date, which should only be those with a date less than the day.
I'm setting it to run daily at 00:01:00
If you can help me see what steps I am omitting or what I am indicating incorrectly.
//##############################
//# VALIDATE EXPIRATION DATE #
//##############################
//GlideDate has methods to work with dates
var chkDate = new GlideDateTime();
//Here what is done is to consult the records that meet the date condition
//expiration
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('active', true);
gr.addQuery('u_expiration_date', '<', chkDate);
gr.query();
//Iterates the records that it finds to send to call the created event and that this
//trigger notification
while(gr.next()){
gr.active = 'false';
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2023 11:31 AM
Hi @Paulo Campos Ch,
Use below script it will work
var chkDate = new GlideDateTime();
chkDate.setDisplayValue(gs.now());
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('active', true);
gr.addQuery('u_expiration_date', '<', chkDate);
gr.query();
while (gr.next()) {
gr.active = false;
gr.update();
}
Please mark this as solution proposed and helpful if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2023 11:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2023 12:23 AM
Hi @Paulo Campos Ch ,
Use below script.
var chkDate = new GlideDateTime();
chkDate.setDisplayValue(gs.now());
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('active', true);
gr.addQuery('u_expiration_date', '<', chkDate);
gr.addQuery('u_expiration_date', '>=', '2023-10-10 00:00:00'); // Greater than or equal to October 10, 2023
gr.addQuery('u_expiration_date', '<=', '2023-10-19 23:59:59'); // Less than or equal to October 19, 2023
gr.query();
while (gr.next()) {
gr.active = false;
gr.update();
}
Please mark this as solution proposed and helpful if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2023 08:50 AM
But it is limiting it to those dates, and I would have to log in every month to change the work schedule, and that is not the idea.
What I want is for the script to validate the expiration date with the current day (today), since as indicated by the scheduled job it will be performing this validation daily at a time of 00:01:00
gr.addQuery('u_expiration_date', '>=', '2023-10-10 00:00:00'); // Greater than or equal to October 10, 2023 gr.addQuery('u_expiration_date', '<=', '2023-10-19 23:59:59'); // Less than or equal to October 19, 2023