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
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
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.
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)
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156