I am trying to create a custom button to change system status in bookable ressource booking entity from work order command bar but it return error
function updateAccount() { var results =null; var recordId = Xrm.Page.data.entity.getId(); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/msdyn_workorders("+recordId+")?$expand=msdyn_msdyn_workorder_bookableresourcebooking_WorkOrder($select=bookableresourcebookingid)", false); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var result = JSON.parse(this.response); var msdyn_workorderid = result["msdyn_workorderid"]; for (var a = 0; a < result.msdyn_msdyn_workorder_bookableresourcebooking_WorkOrder.length; a++) { var msdyn_msdyn_workorder_bookableresourcebooking_WorkOrder_bookableresourcebookingid = result.msdyn_msdyn_workorder_bookableresourcebooking_WorkOrder[a]["bookableresourcebookingid"]; var entity = {}; entity["BookingStatus@odata.bind"] = "/bookingstatuses(C33410B9-1ABE-4631-B4E9-6E4A1113AF34)"; $.ajax({ type: "PATCH", contentType: "application/json; charset=utf-8", datatype: "json", url: Xrm.Page.context.getClientUrl() + "/api/data/v8.2/bookableresourcebookings("+msdyn_msdyn_workorder_bookableresourcebooking_WorkOrder_bookableresourcebookingid+")", data: JSON.stringify(entity), beforeSend: function(XMLHttpRequest) { XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0"); XMLHttpRequest.setRequestHeader("OData-Version", "4.0"); XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, async: true, success: function(data, textStatus, xhr) { //Success - No Return Data - Do Something }, error: function(xhr, textStatus, errorThrown) { Xrm.Utility.alertDialog(textStatus + " " + errorThrown); } }); } } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); Xrm.Page.getAttribute("msdyn_systemstatus").setValue(690970003); }
{"error":{"code":"","message":"Bad Request - Error in query syntax.","innererror":{"message":"Bad Request - Error in query syntax.","type":"Microsoft.OData.ODataException","stacktrace":" at Microsoft.OData.UriParser.SegmentKeyHandler.TryCreateKeySegmentFromParentheses(ODataPathSegment previous, KeySegment previousKeySegment, String parenthesisExpression, ODataUriResolver resolver, ODataPathSegment& keySegment, Boolean enableUriTemplateParsing)\r\n at Microsoft.OData.UriParser.ODataPathParser.TryBindKeyFromParentheses(String parenthesesSection)\r\n at Microsoft.OData.UriParser.ODataPathParser.TryCreateSegmentForNavigationSource(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 Microsoft.OData.UriParser.ODataUriParser.ParsePath()\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.OData.CrmODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer)"}}}
*This post is locked for comments