- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 10:47 AM
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?
Thanks!
Max
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 06:24 AM
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");
}
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 11:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 11:35 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 11:18 AM
You might wanna have a scheduled job, that runs every hour to check and update the record.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 11:33 AM
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.