How to – use booking rules for validation checks in Dynamics 365 Field Service


Through booking rules, we can specify custom JavaScript methods, that can be used to run validation checks, before creation or update of a bookable resource booking record. Based on the result of the validation checks we can either warn the user or cancel the booking create or update event.

Booking rules are triggered when a resource is booked or a bookable resource booking record is either created or updated using the schedule board, schedule assistant, or booking form.

The booking rules are not triggered if the booking form has business process flow enabled. We can also disable the booking rule to be triggered on the save of the booking form by enabling the setting – msdyn_DisableProcessBookingRulesOnSaveBookingForm

Let us see it in action.

Below is our JavaScript method to be used as a Booking Rule.

function Validate(sbContext) {
  
    var url = Xrm.Page.context.getClientUrl();
    var ruleResult = {
        IsValid: false,
        Message: '',
        Type: 'error'
    };
  
    var isScheduleBoard = sbContext.newValues.ResourceScheduleSource;
    var isUpdate = sbContext.isUpdate;

    if (isScheduleBoard === '690970001' && isUpdate === true) {
        ruleResult.IsValid = false;
        ruleResult.Message = 'Booking cannot be updated from the Schedule Board';
        ruleResult.Type = 'error';
    }
    else {
        ruleResult.IsValid = true;
        ruleResult.Message = '';
        ruleResult.Type = '';
    }     

    return ruleResult;
}

To create a Booking Rule, navigate to Resources >> Booking Settings >> Booking Rules inside the Dynamics 365 Field Service app and create a new booking rule, specifying the web resource and the method inside it.

Let us try to update a booking from the schedule board.

This will trigger our booking rule and will pass the context object, which contains details like whether it is a create or update event, and details around old values and new values for start time, end time, resource details, etc. for that booking.

We can use these values passed in the context, fetch more details about the corresponding resource or work order, have our validation logic defined there, and finally pass the ruleResult object.

If we want to cancel the event, we can set IsValid as false, specify the error message, and set Type as an error in the ruleResult object. Similarly, if it passes the validation, we can set IsValid as true.

This is how the error message shows up, and the event is canceled inside the schedule board.

Below we can see the same booking rule being triggered from the Booking Resource Booking form.

We can deactivate the booking rule record created if we do not want it to trigger.

Get all the details here – Booking Rule

Hope it helps..

Advertisements

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

One thought on “How to – use booking rules for validation checks in Dynamics 365 Field Service”

Please share your thoughts

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

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Dynamics 365 Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Knowhere365

Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM