Update just created record.. (Plugin Help) RRS feed

  • Question

  • Hi everyone,
    I am doing a plugin. It run on post operation of the create of an order.
    In the sales order entity we have order products.
    My plugin populates the order product values into another entity (Premium Product History)
    Everything is working fine. However if we have the same order products in an order then I will want to update the (Premium Product History) record instead of creating a new one.
    Sample Code…
    for (int i = 0; i < retrieved.Entities.Count; i++)
                                tracingService.Trace("We have created a Premium Product History");
                                if (retrieved.Entities[i].Attributes["productid"] != orderProducts.Attributes["productid"])
                                    tracingService.Trace("We have created a Premium Product History");
                                    tracingService.Trace("We are updating a Premium Product History");
                                    var updatePremiumProduct = context.OrganizationService.Retrieve("new_premiumproductpurchase", premiumProductHistory.Id, new ColumnSet("true"));
                                    updatePremiumProduct["new_name"] = "Test";
    I noticed that premiumProductHistory.Id is returning an empty Guid.

    How do I get the guid of the just created record: context.OrganizationService.Create(premiumProductHistory); ????

    • Edited by davdatong Wednesday, January 22, 2014 3:23 PM
    Wednesday, January 22, 2014 3:22 PM

All replies