web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Booking rule - Not working - Help me

(0) ShareShare
ReportReport
Posted on by 144

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;
}
}
}

  • Thomas David Dayman Profile Picture
    11,323 on at

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

  • aindike Profile Picture
    144 on at

    No.

    7367.untitled.png

  • aindike Profile Picture
    144 on at

    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)"}}}

  • Verified answer
    Thomas David Dayman Profile Picture
    11,323 on at

    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
    144 on at

    It is working. Thanks

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 > Field Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans