- 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-29-2023 09:27 AM - edited 08-29-2023 09:28 AM
You were actually close. Change:
var edt= new GlideDateTime(dc.getEndDateTime());
edt.getDate(); //<-- this is not actually setting anything
gs.print(edt); //so that is why you still have the time portion here
...to:
var edt= new GlideDateTime(dc.getEndDateTime());
gs.print(edt.getDate()); //will only show the date portion
But if you want a Date object:
var edt= new GlideDateTime(dc.getEndDateTime()); //creates a new Date/Time object
var endDate = new GlideDate(); //creates a new Date object
endDate.setDate(edt.getDate()); //sets the Date object to the date of the Date/time object
gs.print(endDate);
No need splitting things, get the data right from the source.
