Based on active and valid to date is expired on that case we need to make inactive

mani55
Tera Contributor

In incident table we need to check two conditions like active records and valid to date based on this we need to make inactive those records please let me how to archive through server side

3 REPLIES 3

RaghavSh
Kilo Patron

You can write fix script like below:

 

var qry = "active=true^sys_updated_on<javascript&colon;gs.dateGenerate('2025-06-10','00:00:00')"; // encoded query

var rec=. new GlideRecord('incident'); // replace with actual table
rec.addEncodedQuery(qry);
rec.query();
while(rec.next()){
rec.active = false;
rec.update();
}

** Note : You can form your wncoded query by forming filter at topr of your table and then right click on filter and copy query**

** Note : This same code can be used in schedule jon if you want toperform this action periodically.**

 

 


Raghav
MVP 2023

GlideFather
Tera Patron

Hi @mani55,

 

JFYI there is not any other option than server side for database operations 😉

 

There are plenty of methods how to achieve this but the easiest might be by Update Jobs. It's a no-code method - you will create an update job record, select a table, then apply conditions what records to update (click Preview to see what records will be impacted), then select the values to add (e.g. state change, work note addition - "Updated by maintenance job" or something). Then I recommend you uncheck the two checkboxes (one can re-trigger business rules and it could send notifications etc and another will overwrite the updated by and updated on fields, better to keep the original values).

 

Then select when to perform it and it also has a rollback option in case that something goes wrong...

 

For more details please see my reply in another thread about the same:

https://www.servicenow.com/community/developer-forum/ways-to-migrate-all-references-of-a-group-to-a-... 

 

Let me know what do oyu think about this approach

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Ankur Bawiskar
Tera Patron
Tera Patron

@mani55 

what's your actual business requirement?

Incidents will become inactive once they are closed as OOTB behavior.

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