
Hi,
I'm trying to create a BookableResourceBooking record, using the CRM REST Builder v2.6. I'm using the mandatory fields (the same I would use if using a form) but I get an error "400 Bad Request).
In the sample code I'm providing I've the data that I would use in a form, and that works fine. If I try to do the same via Web API, it fails. If I use the SDK it will work just fine, it's just the web api that is requiring something else, and I don't know why. It doesn't show in the code sample, but I tried to add workorder and resource requirement, but still fails.
In the past, I faced the same problem while creating Work Orders, where despite all the mandatory fields being present, I had to add PriceList (which it's a Business Required field) so the web api could accept the request.
Can you help ?
Thanks
var entity = {};
entity["bookingstatus@odata.bind"] = "/bookingstatuses(F16D80D1-FD07-4237-8B69-187A11EB75F9)";
entity.bookingtype = 1;
entity.duration = 30;
entity.starttime = new Date("03/03/2019 03:00:00").toISOString();
entity.endtime = new Date("03/03/2019 03:30:00").toISOString();
entity["resource@odata.bind"] = "/bookableresources(128B9710-FCF2-E811-A2CF-0050568F8CEF)";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/bookableresourcebookings", true);
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.setRequestHeader("Prefer", "odata.include-annotations=\"*\",return=representation");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 201) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
//Handle returned attributes
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
*This post is locked for comments
I have the same question (0)After trial and error here the changes that worked: bookingstatus, resource and resourcerequirement needed schema names :| Why some fields and not all required this, I don't know and makes no sense.
entity.duration = 45;
entity.endtime = new Date("02/01/2019 07:30:00").toISOString();
entity.starttime = new Date("02/01/2019 06:30:00").toISOString();
entity.bookingtype = 1;
entity["BookingStatus@odata.bind"] = "/bookingstatuses(F16D80D1-FD07-4237-8B69-187A11EB75F9)";
entity["Resource@odata.bind"] = "/bookableresources(128B9710-FCF2-E811-A2CF-0050568F8CEF)";
entity["msdyn_workorder@odata.bind"] = "/msdyn_workorders(C08AABA8-7D3B-E911-A2E7-0050568F8CEF)";
entity["msdyn_ResourceRequirement@odata.bind"] = "/msdyn_resourcerequirements(C58AABA8-7D3B-E911-A2E7-0050568F8CEF)";
I don't know if this is allowed, but I'll mark this as answer and leave it here since it may help others