Set Field depending on dates

Max McFa
Tera Expert

Hello All,

I'm looking to set a field (True/False) based on if the current date/time is between two date/time fields.

I believe the best way would be using a client script but would also like to have the condition checked every hour. Can someone suggest the correct way to code the client script?

find_real_file.png

Thanks!
Max

1 ACCEPTED SOLUTION

What you need to do on the form, is to have aclient script and fetch the details of the date fields.

Now pass that on server side, through which you can compare the dates and return your desired value to validate in client script responsey.

Below code snippet should give some idea:

var changeGR = new GlideRecord("change_request");
if(changeGR.get("b0dbda5347c12200e0ef563dbb9a718f")){

var currentDateTime = new GlideDateTime();
var actualStartDate = new GlideDateTime(changeGR.getValue("work_start"));
var actualEndDate = new GlideDateTime(changeGR.getValue("work_end"));

if((currentDateTime > actualStartDate) && (currentDateTime < actualEndDate)){
gs.info("between");
}
else{
gs.info("beyond");
}
}

Best Regards
Aman Kumar

View solution in original post

6 REPLIES 6

sonali panda1
Kilo Sage
You just want it to be checked on form load ? Or you want to perform some activities based on that box checked and you want the data to be stored in the table ?

I'd prefer it checked on change for either of the two date fields. After it is checked I want it saved to the table so I can use it for a couple things. One is a report, another is to prevent INC assignment.

Aman Kumar S
Kilo Patron

You might wanna have a scheduled job, that runs every hour to check and update the record.

Best Regards
Aman Kumar

Yea, that will likely be step 2. I initially need to have it set immediately if the current time is within the start and end dates.