Update exisitng records

VSN
Tera Expert

I have a requirement to create a field in one of the table,, for example, we can consider a new field as Active.

here, my requirement is that if the end date < 2024-03-01, those records need to be marked  Active as false.

how can I achieve this functionality?

5 REPLIES 5

Satishkumar B
Giga Sage
Giga Sage

@VSN  Use a before - update business rule to achieve this.

Condition: current.end_date < gs.dateGenerate('2024-03-01', '00:00:00')

current.active = false;

 

 

please mark my response as helpful accept the solution if it helps you

Allen Andreas
Administrator
Administrator

Hi,

If you're looking to go through and "fix" a lot of old records that meet this criteria, then I would recommend first building your filter as you need in list view (meaning go to the table in question, set the date/time, etc. within the filter), then right-click the breadcrumb filter and choose "copy query".

 

From there, create a fix script using GlideRecord and add the query you copied to an addEncodedQuery line and then set the records to the Active field selection as you need.

 

The benefit of doing this in a Fix script is that this can then be placed within an update set and brought forward to other ServiceNow instances as you need. Otherwise, if this is just for a specific instance, then you could utilize a background script instead (but getting into the habit of using a Fix script is always a good idea).

 

If this is for future created records, then you could accomplish this by a Flow in Flow Designer as well.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Tarasingh26
Tera Expert

Use Fix script to update record and put copy query in gr.addEncodedQuery(" ").

can you please help me with script