The CreatorCon Call for Content is officially open! Get started here.

Set records inactive when end date is reaches

msc
Tera Contributor

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.

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

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)

-Anurag

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @msc 

 

Something similar 

 

https://www.servicenow.com/community/developer-forum/incident-management-i-need-a-background-script-...

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]

****************************************************************************************************************

SP22
Giga Sage

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

Ankur Bawiskar
Tera Patron
Tera Patron

@msc 

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)

AnkurBawiskar_0-1702487659963.png

 

AnkurBawiskar_1-1702487659962.png

 

AnkurBawiskar_2-1702487660476.png

 

 

AnkurBawiskar_3-1702487659959.png

 

AnkurBawiskar_4-1702487660146.png

 

AnkurBawiskar_5-1702487660476.png

 

AnkurBawiskar_6-1702487660140.png

 

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader