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

Hi,

Have you got this working or still looking for a 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