Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Create SalesOrderDetail in Plugin No Populate Amount

(0) ShareShare
ReportReport
Posted on by 40

Hi Guys,

If anyone can help me with this, really appreciatte, i write a plugin that create a Sales Order Detail for Order, but whn i created the amount not bring back automatically from Price list, buen when i added manually it does, my code:

  var orderProduct = new Entity
                    {
                        LogicalName = "salesorderdetail"
                    };

                    orderProduct.Attributes.Add("salesorderid", new EntityReference("salesorder", id_pedido));
                    orderProduct.Attributes.Add("productid", new EntityReference(producto.LogicalName, producto.Id));
                    orderProduct.Attributes.Add("quantity", Convert.ToDecimal(1));
                    orderProduct.Attributes.Add("uomid", new EntityReference("uom", producto.GetAttributeValue<EntityReference>("defaultuomid").Id));
                    service.Create(orderProduct);


05_2D00_Oct_2D00_16-00_2D00_41_2D00_46.png

And no calculate amount and totals, but the product is in the PreceList with amount.

Thanks.

*This post is locked for comments

  • Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    Glat that your problem is resolved. If my answer helped you, then feel free to mark as verified.

  • Suggested answer
    Jose Abad Profile Picture
    Jose Abad 40 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    Hi Yadnyesh,

    My solution was, add the products and later update the record de sales order, and thats it, its work!!   thanks for your support

  • Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    Hi Jose,

    I didn't get it. Can you please help me with an example and also the workflow screenshots?

  • Jose Abad Profile Picture
    Jose Abad 40 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    Yad,

    I think i found the problem:

    • The Order, that is created by Workflow its state code is blocked or something, an then yo can add product but no has recalculation and other details.

    I dont know why the order created "sent" read only, but i test with another Order Open, and the code was right! 

    If you can tell me how change this "state code" in workflow or moment that happen would be apprecite.

    Thnks!!

  • Jose Abad Profile Picture
    Jose Abad 40 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    Yad,

    No, the code orderProduct.Attributes.Add("isproductoverridden", 0); doesnt work, because its accept only Bool values.

  • Jose Abad Profile Picture
    Jose Abad 40 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    Yes, Yad, sure, let me screen the images:

    price list element:

    2_2D00_sale.png

    Product order detail:

    2_2D00_sale.png

    Let me test the code setting in '0' of isproductoverridden for this, and i comment you.

  • Verified answer
    Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    Thanks for the Screenshot. Can you also provide screenshot of the price list item you are selecting in order detail and screenshot of the order detail record created through code?

    Also, can you check if 'Select Product (isproductoverridden)' is set to Existing on order detail record. Try adding below line in the code.

    orderProduct.Attributes.Add("isproductoverridden", 0);

  • Jose Abad Profile Picture
    Jose Abad 40 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    Thans fro response, Yad

    Yes, it does, the setting are ok:

    05_2D00_Oct_2D00_16-07_2D00_21_2D00_58_2D002D00_ventas.png

    But are face still the same problem..

  • Verified answer
    Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    Can you check below setting on your environment?

    Go to Settings > Administration > System Settings.

    Go to Sales Tab and check value of 'Set Pricing Calculation preference'. It should be yes in your case.

  • Jose Abad Profile Picture
    Jose Abad 40 on at
    RE: Create SalesOrderDetail in Plugin No Populate Amount

    hi Yadnyesh,

    Thank you for you response, No the change that you me suggested, not work. my code is:

      var orderProduct = new Entity
                        {
                            LogicalName = "salesorderdetail"
                        };
    
                        orderProduct.Attributes.Add("salesorderid", new EntityReference("salesorder", id_pedido));
                        orderProduct.Attributes.Add("productid", new EntityReference(producto.LogicalName, producto.Id));
                        orderProduct.Attributes.Add("quantity", Convert.ToDecimal(1));
                        orderProduct.Attributes.Add("uomid", new EntityReference("uom", producto.GetAttributeValue<EntityReference>("defaultuomid").Id));
                        orderProduct.Attributes.Add("ispriceoverridden", false);
    
                        service.Create(orderProduct);

    7723.05_2D00_Oct_2D00_16-00_2D00_41_2D00_46.png

    The result is the same thing. the amount of product not automatically load.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans