Quantcast
Viewing all articles
Browse latest Browse all 8223

CRM2011: Trouble creating related entities on pre-event plugin

Hi

Because we have large volumes of sales orders that need to be created as quick as possible and we also have a small number of products, what i have done is the following:

I have created some custom fields for the products on the salesorder entity so that the user simply puts the quanitity in that field when creating a salesorder - as opposed to first saving, then going to order products and adding them.. (long process).

Anyways, i have tested my code in a standard app using web services and it works fine as per below:

Dim neworder As New Entity(SalesOrder.EntityLogicalName)
        neworder.Attributes.Add("customerid", New EntityReference(Account.EntityLogicalName, CustomerGUID)))

        Dim ProductOne As New Entity(SalesOrderDetail.EntityLogicalName)
        ProductOne.Attributes.Add("ispriceoverridden", True)
        ProductOne.Attributes.Add("isproductoverridden", False)
        ProductOne.Attributes.Add("productid", New EntityReference(Product.EntityLogicalName, ProdyctGUID)))
        ProductOne.Attributes.Add("priceperunit", New Money(4.5D))
        ProductOne.Attributes.Add("quantity", 120D)
        ProductOne.Attributes.Add("uomid", New EntityReference(UoM.EntityLogicalName, UoMGUID)))


        Dim ProductTwo As New Entity(SalesOrderDetail.EntityLogicalName)
        ProductTwo.Attributes.Add("ispriceoverridden", True)
        ProductTwo.Attributes.Add("productid", New EntityReference(Product.EntityLogicalName, ProductGUID)))
        ProductTwo.Attributes.Add("priceperunit", New Money(1D))
        ProductTwo.Attributes.Add("quantity", 1D)
        ProductTwo.Attributes.Add("productdescription", "Delivery fee")

        Dim orderitemscol As New EntityCollection
        orderitemscol.EntityName = SalesOrderDetail.EntityLogicalName
        orderitemscol.Entities.Add(ProductOne)
        orderitemscol.Entities.Add(ProductTwo)
        neworder.Attributes.Add("pricelevelid", New EntityReference(PriceLevel.EntityLogicalName, PricelistGUID)))

        neworder.RelatedEntities.Item(New Relationship("order_details")) = orderitemscol

        Console.WriteLine(ICEProx.Create(neworder))

However, when i use the code in a plugin and register it in a pre-event stage, I get no errors but the parent-child related entities do NOT get created.

I then tried to take the entity collection and store it into the "SharedVariables" on the context and created a seperate plugin registered on the post-event, and tried to update the entity by attaching ordered items there. Still no luck.

I guess i will have to perhaps try and update each order item with the parent order ID and update them seperately thru service.

I was hoping to keep it clean and lean by allowing the platform to automatically link the child entities on the main Create event.  I guess this funtionality is not supported.


Rish


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>