Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Field service ressource

(0) ShareShare
ReportReport
Posted on by

Im using Field Service and have a requirement where ressources should only be booked on specific days based on a territory. So if a Ressource is added to a Service Territory, then a rule needs to be applied which provides the possibilities for filtering out specific day (fx Monday), which means that the Ressource can only be booked in that Territory on Monday.

Im unable to find any options for this. Anytime have experience within the area?

*This post is locked for comments

  • Thomas David Dayman Profile Picture
    11,323 on at
    RE: Field service ressource

    Yeah they have no examples to go off.

    I might do some more work on booking rules if i get time and maybe write some blog posts so it can help other users in future.

  • Hussain Iqbal Profile Picture
    on at
    RE: Field service ressource

    Many thanks for the useful response Thomas, much appreciated. I will definitely check it out. Only thing I am wondering about here, is that there is only a little bit of documentation available for the use of Booking Rules.. Microsoft should really provide more documentation and samples here. Thanks again.

  • Verified answer
    Thomas David Dayman Profile Picture
    11,323 on at
    RE: Field service ressource

    Hi Hus,

    I tried creating the booking rule I described above as I haven't really used them before and it would be good practice for me.

    var getResult;
    var getValue;
    
    function newBookingRule(sbContext)
    {
    	debugger;
    	var clientUrl = Xrm.Page.context.getClientUrl();
    	var ruleResult = {
    		IsValid: false,
    		Message: '',
    		Type: 'error'
    	};
    	var resourceReqId = sbContext.newValues.ResourceRequirementId;
        var bookingDate = sbContext.newValues.EndTime.getDay().toString();
    
    	getRecord(resourceReqId, "_msdyn_workorder_value", "msdyn_resourcerequirements");
    	getRecord(window.getValue, "_msdyn_serviceterritory_value", "msdyn_workorders");
    	getRecord(window.getValue, "new_day", "territories");
    	if (window.getValue === bookingDate)
    	{
    		ruleResult.IsValid = true;
    		ruleResult.Message = 'Success';
    		ruleResult.Type = 'success';
    	}
    	else
    	{
    		ruleResult.IsValid = false;
    		ruleResult.Message = 'Work Order cannot be scheduled for this day';
    		ruleResult.Type = 'error'; //also you can use 'warning' - gives you a choice to proceed or not and 'success'
    	}
    	return ruleResult;
    }
    
    function getRecord(RecordId, Value, Entity)
    {
    	var req = new XMLHttpRequest();
    	req.open("GET", encodeURI(Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + Entity + "(" + RecordId + ")?$select=" + Value), false);
    	req.setRequestHeader("Accept", "application/json");
    	req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    	req.setRequestHeader("OData-MaxVersion", "4.0");
    	req.setRequestHeader("OData-Version", "4.0");
    	req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
    	req.send();
    	if (req.readyState === 4)
    	{
    		req.onreadystatechange = null;
    		if (req.status === 200)
    		{
    			window.getResult = JSON.parse(req.response);
    			window.getValue = getResult[Value];
    		}
    		else
    		{
    			Xrm.Utility.alertDialog(req.statusText);
    		}
    	}
    }


    Above is the code I created which kind of does what you specified.

    I added a text field called 'new_day' in the Territory entity. Here you can put the day of the week e.g. the number '2' for Tuesday. This means that when the user moves a job to a slot on Tuesday then it will compare the territory's 'new_day' field on the Work Order to the schedule boards slot day and determine if the Work Order can be allowed to be booked or not.

    This code is not the best and has some bad practices and you may need to expand on but it works.

  • Suggested answer
    Thomas David Dayman Profile Picture
    11,323 on at
    RE: Field service ressource

    I think the best way might be to write a Booking Rule or plugin to check if a booking is placed in a certain territory and that the day is Monday then the booking can go through else throw an error and block the user from doing so.

    example of a booking rule - community.dynamics.com/.../240808

    You might have to add a new field onto the Territory called 'Day' where you can put in the name of the day you allowed to book this territory for.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans