web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Calculated Rollup Fields

(0) ShareShare
ReportReport
Posted on by

I have created a field on a form that is a questionnaire.  The questions are in a sub form. The user will answer Yes or No to each question and the rollup field will calculate the number of answers that have been answered Yes.  The field is working correctly, but it does not calculate immediately after I press save.  I have to click the refresh button next to the field and then the field calculates correctly.  Is there some way to configure the system to recalculate the rollups when the save button is clicked or when the record is changed as an answer is keyed?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Tom,

    Rollup fields are calculated asynchronously - see msdn.microsoft.com/.../dn817863.aspx

    Seems there is a CalculateRollupField message that developers can use to calculate a rollup attribute value on demand - maybe that can help?

    There is also a similar thread, that has some further details community.dynamics.com/.../147140

    Another way that you can achieve a similar outcome, is to use Synchronous Plug-ins, instead of rollup fields - that perform this calculator.

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     you can also try this kind of workflow solutions to calculate rollup fields:

    github.com/.../Dynamics-365-Workflow-Tools

     (actually, all those solutions iwll be using the request mentioned by Radu above.. but that's if you don't want to develop your own code)

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    if you want to see it right away you will need to develop some client-side code, i.e. Javascript function to calculate your rollup filed.

  • Suggested answer
    Yusi Profile Picture
    100 on at

    This problem requires two step solution.

    First you need to invoke the CalculateRollupField either via JS or C#.

    For your requirement, since you need to see the results immediately, I suggest use JavaScript.

    The following JS code will trigger your roll up field recalculation

    function CalculateRollupField(EntityName, recGuid, RollUpFieldName)

    {
    recGuid = recGuid.replace("{", "").replace("}", ""); // String Guid

    var HttpReq = new XMLHttpRequest();

    HttpReq.open(this.method, this.url, true); // Need this to initiate the request

    HttpReq.setRequestHeader("OData-Version", "4.0");

    HttpReq.setRequestHeader("OData-MaxVersion", "4.0");

    // Double Check your API URL, may differ for v9.0
    HttpReq.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + "CalculateRollupField(Target=@p1,FieldName=@p2)?" + "@p1={'@odata.id':'" + EntityName + "(" + recGuid + ")'}&" + "@p2='" + RollUpFieldName + "'", true);

    HttpReq.onreadystatechange = function ()

    {

    if (this.readyState === 4)

    {

    HttpReq.onreadystatechange = null;

    if (this.status === 200)

    {

    var results = JSON.parse(this.response);

    }

    else

    {

    Xrm.Utility.alertDialog(this.statusText);

    }

    }

    };

    HttpReq.send(JSON.stringify({}));

    }

    // You can then retrieve the updated value via JS API call (or fetchXML) & use XRM commands to replace the updated value in the form to display it to user right away 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans