User should not be able to select a day in Record Producer that already has three reservations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 02:26 PM
I have built a record producer that has a reservation start date field. One of my requirements is to not allow a user to select a date that already has three reservations. I understand that I need a script include that can be client callable. I am having trouble calling the field in the record producer and comparing that to the reservations already in my work orders table. Here is what I have thus far for the script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 03:22 PM
Hi @Jeff Loock
Can you please try below code and let me know -
var ReservationCountAjax = Class.create();
ReservationCountAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
reservationDates: function() {
var selectDateParm = this.getParameter('sysparm_date');
var selectedDate = new GlideDateTime(selectDateParm);
var formattedDate = selectedDate.getByFormat('yyyy-MM-dd HH:mm:ss');
var workOrderGR = new GlideRecord('table');
workOrderGR.addQuery('state', 2); // Only get records in the 'In Progress' state
workOrderGR.addQuery('u_reservation_start', '>=', formattedDate);
workOrderGR.query();
var inProgressDates = [];
while (workOrderGR.next()) {
inProgressDates.push(workOrderGR.u_reservation_start.getDisplayValue());
}
// Check if there are three or more reservations for the given date
if (inProgressDates.length >= 3) {
// The date is already reserved
return false;
} else {
// The date is available
return true;
}
},
type: 'ReservationCountAjax'
});
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 04:36 PM
I put a gs.addErrorMessage after line 6 and it seems as though the field value is still not being pulled in from the record producer correctly.