Hi All,
I am working on configuring a booking rule that will prevent bookings in Field Service from being made outside of the Date Window Start and Date Window End fields on the related work order.
I continue to get error message after error message, stating that there is invalid data in the booking rule and that the method was skipped. I cannot see any additional information about the error so I have just been spinning in circles trying to identify why the javascript is encountering issues. Any help with setting this up is greatly appreciated!
Here is the code I have used:
var BookingValidation = {
validateBookingDate: function (context) {
var formContext = context.getFormContext ? context.getFormContext() : context;
var startTime = formContext.getAttribute("starttime").getValue();
var workOrder = formContext.getAttribute("msdyn_workorder").getValue();
var workOrderId = workOrder[0].id;
// Asynchronous call to retrieve work order details
return Xrm.WebApi.retrieveRecord("msdyn_workorder", workOrderId, "?$select=msdyn_datewindowstart,msdyn_datewindowend")
.then(function (workOrder) {
var dateWindowStart = workOrder.msdyn_datewindowstart;
var dateWindowEnd = workOrder.msdyn_datewindowend;
if (dateWindowStart && startTime < new Date(dateWindowStart)) {
Xrm.Navigation.openAlertDialog({ text: "The booking cannot be earlier than the start of the date window." });
return false;
}
if (dateWindowEnd && startTime > new Date(dateWindowEnd)) {
Xrm.Navigation.openAlertDialog({ text: "The booking cannot be later than the end of the date window." });
return false;
}
return true;
})
.catch(function (error) {
console.log("Error retrieving work order: " + error.message);
Xrm.Navigation.openAlertDialog({ text: "An error occurred while retrieving the work order details." });
return false;
});
}
};

Report
All responses (
Answers (