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 CRM (Archived)

Dynamics CRM 365 - Create Sales Order Detail with WEB API

(0) ShareShare
ReportReport
Posted on by

Hello Everyone,

Through the use of the 8.0 WEB API and JavaScript, I am trying to create a product on the Sales Order that is open at the time.

Attempting to create even the most simplistic of products under the Sales Order is resulting in an error message.

Here is a link to a CRUD Library of the new WEB API that I am using due to its similarity with the SDK.REST library for previous versions of CRM.

http://www.zacrmguy.com/js-crud-operations-with-web-api-in-crm-2016/

Here is a snippet of the basic code that I am using in my web resource:

var thisOrderId = Xrm.Page.data.entity.getId();

thisOrderId = thisOrderId.replace("{", "").replace("}", "");

var newProduct = new Object();

newProduct["salesorderid@odata.bind"] = "/salesorders(" + thisOrderId + ")";

newProduct["priceperunit"] = 35.0000;

newProduct["quantity"] = 1.0000;

SDK.WEBAPI.createRecord(newProduct, "salesorderdetails", function () { }, function (error) { alert(error.message);}, function () { });


I have also tried this without the priceperunit or the quantity what I am receiving what appears to be the same error message:

Developer tools shows a response of error code 500 with the following in the response body: "Error in CreateOrderDetail."

Would anyone happen to know if there is a required field that I am missing for a SalesOrderDetail or know what might be going on with this?

I appreciate any and all advice.

Thanks so much!
 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    The required field varies based on the type of the product you are trying to add i.e.

    If WriteIn then you need to pass the "Product Description" & "Price Per Unit"

    If Existing Product then "Product Id" & "Default Unit".

    Also, you need to parse the values of quantity & price per unit to to integer

    Below are the sample code for Write In & Existing Product-

    // WriteIn Product

    var newProduct= {};

    newProduct["salesorderid@odata.bind"] = "/salesorders(D6B5E701-A0C9-E711-8127-480FCFF12AC1)";

    newProduct.isproductoverridden = true;

    newProduct.productdescription = "ABC25";

    newProduct.priceperunit = Number(parseFloat(25).toFixed(2));

    newProduct.quantity = parseInt(25);

    // For Existing Product

    var newProduct = {};

    newProduct["salesorderid@odata.bind"] = "/salesorders(D6B5E701-A0C9-E711-8127-480FCFF12AC1)";

    newProduct.isproductoverridden = false;

    newProduct["productid@odata.bind"] = "/products(428E15F5-A0C9-E711-8127-480FCFF12AC1)";

    newProduct["uomid@odata.bind"] = "/uoms(79F19CBF-07E2-4EF3-9C9E-B913821F553F)";

    newProduct.quantity = parseInt(19);

    newProduct.ispriceoverridden = true;

    newProduct.priceperunit = Number(parseFloat(19).toFixed(2));

    I hope this helps. If my post answers your question, please mark as "Verified"

  • Community Member Profile Picture
    on at

    Ravi,

    Once again, I truly appreciate your help.

    Thanks so much!!

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans