The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How can I set a boolean field value based of date?

jmichael
Kilo Contributor

I have a requirement to set a value on a change form based off of the planned end date.

Requirement::

Set 'Field A' to true if record is within 7days of scheduled completion.

Set 'Field A' to false if state is set to "In Review"

Two questions on this, I'm currently using true/false, should I be using a choice value of Y/N? Additionally, this should be set up as a business rule (I think) do I need a scheduled job as well?

Thanks in advance for the help!

4 REPLIES 4

Robert Beeman
Kilo Sage

Hello jmichael,



You can use either variable type you prefer. For True/False you would just set it to the Boolean of true or false respectively. You'll probably need a scheduled job to check if the current date is within 7 days of scheduled completion, and a business rule that runs on insert or update to monitor the state change.


Thanks Robert!



Is there a standard scheduled job template I can follow anywhere? I've not created one before. I would like it to be if this field (planned_end) is within 7days of date set then set my other field (under_review) to true.



Is that logical?



Thanks


-John


you need to run a BR on display to set true/false value when record is queried or displayed. Use GlideDate API to calculate the number of days.


I don't think there is a standard template, but something like this as a daily scheduled job should work.



updateChange();



function updateChange() {


      var sevenDays = gs.daysAgo(-7); // Add seven days to now



      var gr = new GlideRecord("change_request");


      gr.addQuery('planned_end', "<", sevenDays);


      gr.query();



      while (gr.next()) {


              gr.under_review = true;


              gr.update();


      }


}