locked
Why CalculateRollupFieldRequest is not working in Dynamics 365 RRS feed

  • Question

  • Hi,

        I have a situation where I need to recalculate roll-up field when ever a child records are Created, Updated, Deleted, I do it based on parent Id in child record.

       Following is by code, When I debugged this code, its executing fine, but roll-up field is not getting refreshed.

    var myEntity = (Entity)localContext.PluginExecutionContext.PostEntityImages["OpportunityProduct"];
     
    Entity rollupEntity = localContext.OrganizationService.Retrieve("new_myrollupentity", ((EntityReference)myEntity.Attributes["myrollupentityid"]).Id, new ColumnSet("new_totalcost"));
    
    CalculateRollupFieldRequest rollupRequest =
    new CalculateRollupFieldRequest { Target = new EntityReference("new_myrollupentity", ((EntityReference)myEntity.Attributes["myrollupentityid"]).Id), FieldName = "new_totalcost" };
    
    CalculateRollupFieldResponse response = (CalculateRollupFieldResponse)localContext.OrganizationService.Execute(rollupRequest);
    
    rollupEntity = response.Entity;
    
    localContext.OrganizationService.Update(rollupEntity);

    Any one have faced similar problem? Any solution for this ?

    Thanks in advance for your time and help...



    Thanks Regards Prashanth Kamasamudram Even the least work done for others awakens the power within; even thinking the least good of others gradually instills into the heart the strength of a lion.


    Wednesday, February 15, 2017 6:16 AM

All replies

  • Try this site, its has a comprehensive gotchas on roll up fields:

    http://survivingcrm.com/2015/02/crm-2015-rollup-fields-gotchas/

    You may be better off using JavaScript for real time updates of the field.

    • Proposed as answer by Kristian Cole Thursday, February 16, 2017 12:57 PM
    Thursday, February 16, 2017 9:47 AM
  • If you can debug the code and see what is value of new_totalcost after Execute call, does it have new calculated value. To me it looks like Update call is failing here.

    MaKeer

    Thursday, February 16, 2017 8:22 PM
  • Well, its working fine now, issue was there was another requirement conflicting with what I was working on, there was another field. value in extended amount field was zero which should be calculated automatically but in certain conditions it remains zero, which in turn anyway makes my rollup field total to zero and thats the reason it looked like not calculating.

    Thanks Regards Prashanth Kamasamudram Even the least work done for others awakens the power within; even thinking the least good of others gradually instills into the heart the strength of a lion.

    Thursday, April 6, 2017 12:00 AM