Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamics CRM 365 - Create Sales Order Detail with WEB API

Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics CRM 365 - Create Sales Order Detail with WEB API

    Ravi,

    Once again, I truly appreciate your help.

    Thanks so much!!

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Dynamics CRM 365 - Create Sales Order Detail with WEB API

    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"

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans