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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

SDK.REST.createRecord SalesOrderDetail return error 400 The request should be a valid top-level resource object V8.2 on premises

(0) ShareShare
ReportReport
Posted on by

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 

I have the same question (0)
  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    Thank you for your query.

    Did you try using bind with sales order, for example, to set sales order id:

    orderitem["salesorderid@odata.bind"] = "/salesorders(<id>)" 
  • Path1n1 Profile Picture
    on at

    hi, I have retry my second code using data/api , i found out it works and create the order item but return crash report in debug mode. but there is no errors in script .

    CrashReport:
    		FileName:
    		LineNumber:0
    		Function:
    		ErrorReport:
      1.0
      
       Script error.
       0
       
       /{637610856290000019}/WebResources/my_webresourcename
       
       
       
       
      
      
       Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.64
       undefined
       undefined
       undefined
       1920x1080
       Web
       Online
       2021-07-05T13:42:35
      
    

    any idea 

  • Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    Are you sure this error is cause by the code to create Sales Order.

    This crash report is from a web resource, please debug the web resource code.

    Furthermore, if this problem is solved (creating order), please marke the approriate answer as verified (click 'Yes' under 'Did this answer your question?').

    Also, it is recommened to please open a seperate thread for a different issue.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 41

#2
Martin Dráb Profile Picture

Martin Dráb 36 Most Valuable Professional

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans