locked
Plugin RRS feed

  • Question

  • CRM 2016

    I have a custom entity new_Tset which is a parent to New_TTran. I have 2 calculated roll up fields on new_TSet which count the number of child records and the sum of the value in New_TTran.new_val

    The problem I am getting is that if a record is added, amended or deleted to new_TTran , the rollup fields are not being updated.

    I have looked into this and tried several workflow examples but none seem to work and everything points towards a plugin to do this task. Can anyone point me in the right direction please


    Dont ask me .. i dont know

    Tuesday, June 14, 2016 8:31 AM

All replies

  • Hi Pete,

    To begin with, the rollup fields are calculated once an hour (https://msdn.microsoft.com/en-us/library/dn817863.aspx).  To do a plugin that calculates things on child records and populates the parent, have a look at the example codes in the SDK to start with plugnins and then what you want to do is the following:

    * A plugin that fetches all child records that has the same parent as the one you're working on (Retrieve all objects of type regardingfield.logicalname with id regardingfield.id), and that fetch needs to include the field you want to calculate from. Calculate the sum or what it is you want to do, and then update the parent object which will be something like this: 

    Entity updateEnt = new Entity("new_ttran");
    updateEnt.Id = parentObject.Id;
    updateEnt.Attributes.Add("targetfield", calculated_value);
    service.update(updateEnt);
     * This plugin need to be run on create of new_ttran plus on update of that field on new_ttran

    * I would run this plugin post stage since it doesn't update the record it's running on.

    Hope it helps some.


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Tuesday, June 14, 2016 10:17 AM