Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Field Service forum / Booking rule - Not wor...
Field Service forum

Booking rule - Not working - Help me

Posted on by 140

Following highlighted part is not working

function newBookingRule(sbContext) {
debugger;
var ruleResult = {
IsValid: true,
Message: '',
Type: 'success'
};
var resourceReqId = sbContext.newValues.ResourceRequirementId;
var resourceId = sbContext.newValues.ResourceId;

var workOrderId = getRecord(resourceReqId, "_msdyn_workorder_value", "msdyn_resourcerequirements");
var WorkTerritoryId = getRecord(workOrderId, "_msdyn_serviceterritory_value", "msdyn_workorders");

var string = "/api/data/v8.2/msdyn_resourceterritory?$select=_msdyn_territory_value,_msdyn_resource_value&$filter=_msdyn_territory_value eq" + WorkTerritoryId + "and _msdyn_resource_value eq" + resourceId;
var result=getRecords(string)
if (result) {
ruleResult.IsValid = true;
ruleResult.Message = "Success";
ruleResult.Type = '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);
return getResult[Value];
}
else {
Xrm.Utility.alertDialog(req.statusText);
return null;
}
}
}

function getRecords(newQuery)
{
var req2 = new XMLHttpRequest();
req2.open("GET", encodeURI(Xrm.Page.context.getClientUrl() +newQuery), false);
req2.setRequestHeader("Accept", "application/json");
req2.setRequestHeader("Content-Type", "application/json;charset=utf-8");
req2.setRequestHeader("OData-MaxVersion", "4.0");
req2.setRequestHeader("OData-Version", "4.0");
req2.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
req2.send();
if (req2.readyState === 4) {
req2.onreadystatechange = null;
if (req2.status === 200) {
return true;
} else {
Xrm.Utility.alertDialog(req2.statusText);
return false;
}
}
}

  • aindike Profile Picture
    aindike 140 on at
    RE: Booking rule - Not working - Help me

    It is working. Thanks

  • Verified answer
    Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: Booking rule - Not working - Help me

    I think the entity might be called - 'msdyn_resourceterritories'

    Double check to see if your query has all the entity and field names spelt correctly.

  • aindike Profile Picture
    aindike 140 on at
    RE: Booking rule - Not working - Help me

    When I enter a query in url it gives following error

     

    https://..........................-dev.crm6.dynamics.com/api/data/v8.2/msdyn_resourceterritory

    {"error":{"code":"0x8006088a","message":"Resource not found for the segment 'msdyn_resourceterritory'.","innererror":{"message":"Resource not found for the segment 'msdyn_resourceterritory'.","type":"Microsoft.OData.UriParser.ODataUnrecognizedPathException","stacktrace":"   at Microsoft.OData.UriParser.ODataPathParser.CreateDynamicPathSegment(ODataPathSegment previous, String identifier, String parenthesisExpression)\r\n   at Microsoft.OData.UriParser.ODataPathParser.CreateFirstSegment(String segmentText)\r\n   at Microsoft.OData.UriParser.ODataPathParser.ParsePath(ICollection`1 segments)\r\n   at Microsoft.OData.UriParser.ODataPathFactory.BindPath(ICollection`1 segments, ODataUriParserConfiguration configuration)\r\n   at Microsoft.OData.UriParser.ODataUriParser.Initialize()\r\n   at System.Web.OData.Routing.DefaultODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer, Boolean template)\r\n   at System.Web.OData.Routing.DefaultODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer)\r\n   at Microsoft.Crm.Extensibility.ODataV4.Routing.CrmODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer)"}}}

  • aindike Profile Picture
    aindike 140 on at
    RE: Booking rule - Not working - Help me

    No.

    7367.untitled.png

  • Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: Booking rule - Not working - Help me

    Did you check the debugger to see what is happening step by step? Is the query not returning any results?

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans