web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Unanswered

Booking Rules

(0) ShareShare
ReportReport
Posted on by 20

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;
 });
 }
};
Categories:
  • CU26071520-1 Profile Picture
    20 on at

    Hi everyone, 

     

    I am still working towards this. It's funny, it seems like this functionality should be supported out of the box! Any assistance with setting up this booking rule is greatly appreciated.

     

    Thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 381 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 340

#3
WarrenBelz Profile Picture

WarrenBelz 187 Most Valuable Professional

Last 30 days Overall leaderboard