- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 07:02 AM
I am working on creating a Catalog Item. One of the Variables is "Due Date". I need to adding checking/validation to this field so that the user cannot enter any date prior to the next business day. So since today is Friday 8/25/2023, the earliest date they could choose for this field is Monday 8/28/2023.
I found some code in the community we can reference our "Weekdays excluding holidays" schedule, and if we tell it to go 24 hours, it goes to the next Business day. The issue is, it calculated a time component along with it, and we do not want that. We just want the date portion. The Variable in the Catalog Item is a straight date field, with no time component. We just want to make sure that the day they enter is not before the next business day.
Here is the code I have. I am currently just running it in a background script to see what it returns. And it returns 8/28/2023 along with a time component:
var gdt = new GlideDateTime();
var dc = new DurationCalculator();
dc.setSchedule('8746beb20ffb9a00e3b522d8b1050ebf'); //Weekdays excluding holidays schedule
dc.setStartDateTime(gdt);
dc.calcDuration(24*3600); //1 business day = 24 hours
var edt= new GlideDateTime(dc.getEndDateTime())
edt.getDate();
gs.print(edt);Does anyone know how I can accomplish this task, of creating this Catalog Client Script to verify the date entry?
If it is not possible to remove the time piece of my calculated date, maybe I can take the date entered and add 23:59 to it, and use that for comparison purposes (so it would be taking the entered date and making it 11:59 PM on that day, so the comparison will work properly).
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 07:27 AM
Hi,
In the background script you can try this
var edt= new GlideDateTime(dc.getEndDateTime());
edt = edt.toString().split(' ');
var date = edt[0];
gs.print(date);
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 07:27 AM
Hi,
In the background script you can try this
var edt= new GlideDateTime(dc.getEndDateTime());
edt = edt.toString().split(' ');
var date = edt[0];
gs.print(date);
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 09:58 AM
I see that is converting it to a string. Is that going to present a problem if I then use it in a comparison against a date variables?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 07:17 AM
you can try it with a string, but if problem with string occurs , create the string back to date
example :
new GlideDate(string);
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 07:16 AM
This last update returns an error, but when I went back and tested your original solution, it worked! I am a little surprised, as I thought it would return a String value. Not sure I understand why that doesn't seem to matter, but I am happy it works, whatever the reason is!
So thank you!!!
