Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

To mark checkbox to true depending on valid to date.

Sam Hanson
Tera Contributor

Hi Peeps,

I have active field -checkbox- on cmn_cost_center table. Now I want to make checkbox to true depending on valid to date. For that reason I created the below BR

Name : Set active to True 

AFTER - Insert, Update.

 

(function executeRule(current, previous /*null when async*/) {

// Get the "valid to" and current date
var validToDate = new GlideDateTime(current.valid_to);
var currentDate = new GlideDateTime();

// Check if "valid to" date is in the future
if (validToDate > currentDate) {
// Set the "active" field to true
current.active = true;
}

})(current, previous);
 
I have 2 questions here
1) do I need to create any conditions on this BR.
2) do I need to create a fix script to mark the existing cost centers active??
 
can anyone give me the best practice here

 

5 REPLIES 5

Will this work?

JamesChun_0-1712093229423.png

 

valid_toRELATIVEGT@minute@ahead@0