Set records inactive when end date is reaches
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 08:34 AM
Hi everyone,
I have a requirement that I need to inactive records based on end date.
When end date is reached then I have to inactive the record itself.
Could you please help me on this requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 08:43 AM
I would suggest a scheduled job for this.
You can run the job once a day in non business hours, and close out all the records where end date is today (or Yesterday)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 08:46 AM
Hi @msc
Something similar
https://www.servicenow.com/community/itsm-forum/setting-incident-to-active-false/m-p/2570308
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 09:01 AM
Hi @msc ,
Please find the below script and let me whether it is useful or not.
// Create a GlideRecord query for the table (for example, 'incident')
var gr = new GlideRecord('incident');
gr.addQuery('active', true); // Filter for active records
gr.addQuery('end_date', '<=', gs.nowNoTZ()); // Filter for records where end date is in the past or present
gr.query(); // Execute the query
while (gr.next()) {
gr.setValue('active', false); // Set active field to false for those records
gr.update(); // Update the record
gs.info('Record marked inactive: ' + gr.number); // Log the record number for reference
}
Thanks
SP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 09:15 AM
I would recommend flow for this with no-code, low-code approach
I shared something similar earlier, just enhance it for your case
1) Flow Trigger Daily 23:00:00
2) Use Lookup Records action on your table to check if end date is today
3) Then use For Each to iterate over those records
4) then use Send Email action (You use Update Record action)
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader