Universal Resource Scheduling (URS) includes a great feature to extend the Schedule Board functionality to apply specific custom logic and alert Dispatchers when they create or update a Bookable Resource Booking records. This feature is known as Booking Rules. Booking Rules are not to be confused with Booking Alerts. Booking Alerts has a different purpose and we can discuss this in another article.
Out-of-the-box, URS provides effective ways to filter resource requirements, resources, and efficiently book Work Orders (or any schedulable entity) to a suitable resource. In certain scenarios, we need to apply additional logic before creating or updating a Booking (aka Bookable Resource Booking entity).
Example Scenarios:
Display a warning to the dispatcher if he/she attempts to assign a Work Order to a Resource who is not one of the Preferred Resources defined using the Requirement Resource Preference related to the Work Order.
Display a warning to the dispatcher if he/she attempts to assign a Work Order to a timeslot outside the Time Promised From/To range.
Display an error to the dispatcher if he/she attempts to assign a Work Order to a Resource who is defined as Restricted defined using the Requirement Resource Preference, with Preference Type = Restricted, related to the Work Order.
Display an error to the dispatcher if he/she attempts to update an existing Booking by dragging and dropping onto another Resource and the new Resource is already assigned to another Work Order in the same timeslot.
You can think of many scenarios where Booking Rules can be used to apply business logic when creating and/or updating Bookings.
Notification Types
There are two different types of notifications.
- Error – Displays a message and cancels the transaction.
- Warning – Displays a message and allows the user to cancel or continue with the transaction.
To define the Notification Type, set the ruleResult.Type to ‘error’ or ‘warning’.
How to Trigger a Booking Rule
There’s an excellent article in docs.microsoft.com which describes how to create a Booking Rule – Set up booking rules. In this generic example, a custom action is triggered by the JavaScript code. The Custom Action is a configuration feature which allows a Functional Consultant to extend the functionality without a Developer. I highly recommend reviewing this article.
For a more simple explanation please see below.
Step 1 – Create a JavaScript Web Resource.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
function BookingRule1(sbContext) { debugger; /* Please delete this line before deploying to Production */ // Standard JavaScript Alert alert("Start Business Rule ..."); var ruleResult = { IsValid: false, Message: '', Type: 'error' }; // Access the data var resourceReqId = sbContext.newValues.ResourceRequirementId; var newStartTime = sbContext.newValues.StartTime; var newEndTime = sbContext.newValues.EndTime; // Xrm Alert Dialog Xrm.Utility.alertDialog(resourceReqId); // Xrm Confirm Dialog Xrm.Utility.confirmDialog("Are you sure?",yesCloseCallback,noCloseCallback) // Your rule here var ruleOutput = 1; // Dummy if(ruleOutput == 1) { ruleResult.IsValid = true; ruleResult.Message = "Success"; ruleResult.Type = 'success'; } else if(ruleOutput == 2) { ruleResult.IsValid = false; ruleResult.Message = "Rule failed. Transaction will be cancelled!"; ruleResult.Type = 'error'; } else { ruleResult.IsValid = false; ruleResult.Message = "Rule warning. To ignore the warning and continue, click Continue. Otherwise, click Cancel."; ruleResult.Type = 'warning'; } alert("End Business Rule ..."); return ruleResult; } function yesCloseCallback() { alert("You said OK!"); } function noCloseCallback() { alert("You said Cancel!"); } |
Step 2 – Create a Booking Rule Record
- Select the JavaScript Web Resource
- Specify the function name
That’s it. Now, whenever a Bookable Resource Booking record is created or updated through the schedule board or from the Bookable Resource Booking form, JavaScript function will trigger.
References
Docs – Set up Booking Rules – https://docs.microsoft.com/en-us/dynamics365/customer-engagement/field-service/set-up-booking-rules
Docs – Booking Alerts – https://docs.microsoft.com/en-us/dynamics365/field-service/booking-alert
Credit – Header Image – https://www.pinterest.com.au/pin/313774299016874614/
Thank you for visiting Dyn365Apps.com.
Follow me on Twitter – Follow @dyn365apps
Until next time…
About the Author
Nadeeja Bomiriya is a Microsoft MVP, Chapter Lead – Dynamics 365 and Power Platform Saturday – Australia, Sri Lanka, Committee Member – Melbourne Dynamics 365 User Group, Technical Architect, and Dynamics 365 Practice Lead who lives in Melbourne, Australia.
Disclaimer: This blog post contains opinions of my own and not the views of my employer.