Field Service – Booking Rule example

In this article I will go into detail of creating a Booking Rule and will also show an example of one.


Below is a working piece of source code which when a Resource Requirement is placed on the Schedule Board, runs a query to retrieve the Work Order ID and display it on the users screen.



Firstly you will to create a new Web Resource and add it as a new Booking Rule. You will need to add the name of the method that you intend to run which in this case is ‘newBookingRule‘.


To trigger the booking rule you will need to drag a Resource Requirement onto an open slot on the schedule board.


My Booking rule will display an alert which will show the Work Order ID.


Now I will go into more detail on what my code is doing for more clarity.

As you can see I am passing a value called ‘sbContext‘ into my ‘newBookingRule’ method. Below you can see what type of values you have access to when this Booking rule gets executed. In this case I want to get the ‘ResourceRequirementId’ which I can use to get the Work Order ID later.


Below is the ‘ResourceRequirementId’ which i’m retrieving.


Next I will use that ‘ResourceRequirementId’ value and use it to execute a query to get the Work Order ID.


As you can see the query has worked and my ‘req.response‘ value is bringing back the JSON I need to get the Work Order ID.


Below is the WorkOrderId I am retrieving.


Finally the last piece of the code is for deciding if the Booking should be blocked or not. In this case I am checking if the ‘workOrderId’ contains a value. If it contains a value then go ahead and Book the Work Order and also show an alert displaying the Work Order ID.


That’s it! Hopefully with my basic example code you can go and achieve more advanced requirements. 🙂


I tested this Booking Rule in Dynamics 365 V9.




9 thoughts on “Field Service – Booking Rule example

  1. Thanks for the article Thomas! Any suggestions what would be the simplest way to automatically create a booking for an existing Work Order for a preferred resource? So the process is: agreement -> booking setup -> work orders (preferred resource is named) -> automatic booking of preferred resource.

    1. Hi Antti,

      I think this should be already be doable out of the box? If you set up a Booking Setup and select a preferred resource. Depending on what the Recurrence pattern is it should create a booking for you.

      If you are looking for something else. Then you could just create a booking via a workflow when a Booking Setup is created when a Preferred Resource contains data? Let me know if you need anything else.

  2. Hi Thomas.

    Thanks for the article. i have been trying to make one little js work whith the schedule boad but it seem it is not executing the script

    its a very simple script with an alert message but it dosnt work. i follow all the stept regarding to the booking rule and the format of the return object in the script but nothing so far. any hint would be much appreciated

    function newBookingRule(sbContext)
    var url = Xrm.Page.context.getClientUrl();
    var ruleResult = {
    IsValid = false,
    Message = ”,
    Type = ‘error’,



    ruleResult.IsValid = false;
    ruleResult.Message = ‘Some Error Message Here.’;
    ruleResult.Type = ‘error’;

    return ruleResult;


    1. Hi Anthony,

      Sorry for the late reply but I was very busy. Im not sure what was going wrong with your code but I have fixed your code below:

      function newBookingRule(sbContext)
      var url = Xrm.Page.context.getClientUrl();
      var ruleResult = {
      IsValid: false,
      Message: '',
      Type: 'error'



      ruleResult.IsValid = false;
      ruleResult.Message = "Some Error Message Here.";
      ruleResult.Type = "error";

      return ruleResult;


  3. Nice Article. Is there a way to hide the “Please review Booking Rule warnings” dialog if workorderId is not found. I mean if workOrderId is available display the alert message else no alert message.

    1. Hi Pankaj,

      I think I know what you are saying. I personally haven’t been able to hide the “Error message” from appearing if you want to prevent the booking. You may want to try changing ruleresult.Type? I’m not sure what other values it can take.

  4. Hi Thomas,

    I was following your method of using Booking Rule, but realized that when the booking is made via the Dynamics Portal, the booking is done using the api so the booking rule js won’t be enforced.

    Which means I have to use a plugin, but unsure how the plugin will reference the resource requirement specified in the resource booking.

    Any help you’re able to offer is greatly appreciated.


    1. Hi Sudhir,

      For plugin you will need to make it synchronous and on create.

      There should be a Resource Requirement field on the Bookable Resource Booking which you should be able to reference

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.