hi ,
I have a html web resource where I need to generate a order and add items to order. I can create a order but when I tried to add order items it fails. I tried with ajax XMLHttpRequest , SDK.REST.createRecord
both failed .
var orderitem = {}; orderitem.IsProductOverridden = false; orderitem.ProductId = { Id: "d270cd0e-a589-e811-80e2-005056be003c", LogicalName: "product" }; orderitem.SalesOrderId = { Id: "07A5E897-B2D9-EB11-8111-0050569DDB30", LogicalName: "salesorder" }; orderitem.UoMId = { Id: "455469c8-601f-e211-9c7d-005056be0040", LogicalName: "uom" }; orderitem.Quantity = { Value: "1" }; orderitem.IsPriceOverridden = true; orderitem.PricePerUnit = { Value: "349.00" } ; SDK.REST.createRecord(JSON.stringify(orderitem), "SalesOrderDetail", function success(result) { console.log("created" result.Id); }, function (error) { console.log(error.message); } );
this returns "400: Bad Request: Error processing request stream. The request should be a valid top-level resource object " ... the Ids I am passing definitely in the system. ans i have tried the same code with passing Name values of the entity references as well. but no luck. I have tried to add write-in order items , that also failed.
I also tried to use Instance Web API xxxxxxxxxxxx/.../ didn't work either. I tired parent.Xrm.WebAPI but that returns error undefined and I saw Xrm.webAPI not enable in V8
var newProduct = {
"salesorderid@odata.bind": "/salesorders(07A5E897-B2D9-EB11-8111-0050569DDB30)",
"isproductoverridden": false,
"productid@odata.bind": "/products(d270cd0e-a589-e811-80e2-005056be003c)",
"uomid@odata.bind": "/uoms(455469c8-601f-e211-9c7d-005056be0040)",
"quantity": parseInt(1),
"ispriceoverridden": true,
"priceperunit": Number(parseFloat(349).toFixed(2))
};
var req = new XMLHttpRequest();
req.open("POST", "https://xxxxxxxx/api/data/v8.2/salesorderdetails", true);
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.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 200) {
console.log("success");
} else {
var error = JSON.parse(this.response).error;
console.log(error.message);
}
}
};
req.send(JSON.stringify(newProduct));
Could any one help me to resolve this please. I can create orders and order items using server side c# scripting using a custom workflow activity , but I want to approach this from html web resource and need crm user to input few things to pass to order items which cannot be done via workflow. looking forward experts answers.
thank you