locked
populate field in product by summing the product list item fields RRS feed

  • Question

  • Hi,

    I created a new enetity product list item and added this in product form as a subgrid.

    I have a field field1 in product form as "total

    product list entity has two custom fields- number field 1 and number field 2

    when i add a product list item to product ..... the sum of this 2 fields should fall in product "total"

    how do i do this using a plugin....


    Tuesday, June 3, 2014 8:02 AM

Answers

  • Hi,

    Create a Plugin and register it on Create/Update of Product List entity. Whenever, a Product List item is created or updated, fetch it's parent Product (you'll get this from a Product lookup in Product List). Sum up your fields (1 and 2) and update the Product entity accordingly.

    But if you're adding Product List items from the Product form (in the subgrid), the updated Total value won't be updated on the Product form automatically, you'll need to refresh the Product form.


    Admin QuikView Solution for CRM 2013

    • Marked as answer by Amy.4 Friday, June 6, 2014 4:49 AM
    Tuesday, June 3, 2014 8:10 AM

All replies

  • Hi,

    Create a Plugin and register it on Create/Update of Product List entity. Whenever, a Product List item is created or updated, fetch it's parent Product (you'll get this from a Product lookup in Product List). Sum up your fields (1 and 2) and update the Product entity accordingly.

    But if you're adding Product List items from the Product form (in the subgrid), the updated Total value won't be updated on the Product form automatically, you'll need to refresh the Product form.


    Admin QuikView Solution for CRM 2013

    • Marked as answer by Amy.4 Friday, June 6, 2014 4:49 AM
    Tuesday, June 3, 2014 8:10 AM
  • If your requirement is to add the total of all the filed 1 and field 2 values from all the product list items related to the product, make sure you retrieve all the records in your post create/update plugin.

    Tuesday, June 3, 2014 6:05 PM
  • Hi , iam using this code but unable to retrieve the lookup id.. can you help me with this ...

       if (entity.LogicalName == "new_productlineitem")
                        {
                            int t = Convert.ToInt32(entity.Attributes["new_numberfield2"]);
                            int p = Convert.ToInt32(entity.Attributes["new_numberfield1"]);
    
                            int result = Convert.ToInt32(t) + Convert.ToInt32(p);
    
     EntityReference ProductLookup = (EntityReference)entity.Attributes["new_product_pliid"];


    Thursday, June 5, 2014 4:44 AM
    • Proposed as answer by F.Kuyler Thursday, June 5, 2014 9:07 AM
    Thursday, June 5, 2014 9:07 AM