Hello Experts,
I kind of know it is not possible, but is there any supported / unsupported way to force the form to recalculate a roll-up field through JavaScript. If not possible through JS what about through a plugin?
Looking forward to hear
AbD
*This post is locked for comments
it's not possible from JS, in my opinion you must create a normal number field and you calculate with js
Yes , the code below works perfect for me.
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 and use XRM commands to replace the updated value in the form
Hi Drew, thank you thank you it works! I didn't figure out how simple is. Thanks again, have a nice day. Walter
Hi Walter,
The tool I mentioned has been rolled into Demian's Workflow tools I think... This is what I have been using for past couple of implementations.
https://github.com/demianrasko/Dynamics-365-Workflow-Tools
The field name should be the "Name" of the field, not the schema name of the field. This is actually a documentation fix I had them update recently.
https://github.com/demianrasko/Dynamics-365-Workflow-Tools/issues/12
As far as the parent entity dynamics field, you should be able to select the Account entity and then there will be a field in the list called Record URL (Dynamic) which will point to it.
Let me know if does not work.
Thanks!
Hi drew, sorry if I'm bothering you, I'm experiencing your same needs but I'm not able to solve my problem.
I have the entity "Credits" that have a field named Quantity. The parent entity is Account, that has a rollup field named CreditSum. All works fine, each Account's rollup field CreditSum is correctly updated (manually or every 12 hours) with the sum of the corresponding Credits.
Now I'm trying to setup the Workflow like you did, that executes a rollup each time I add, modify, delete a record in the Credits table, but the Workflow stops with an error. I'm wasting hour and hours because I don't know what to enter to the fields Fieldname and Parent Record URL.
Thank you for your help. Sorry for my poor english!
Yes. Your are right. But that can be handled through the coding logic like using flag variable or something like that. Also, I strongly recommend to not go for unsupported development.
Also, there does not seem to be any supported way unless the one I mentioned in my earlier comment.
Thank you Mr. Yadnyesh,
had thought of this but below are my issues:
1) The reason I mentioned my CRM version (2015 on-premise) is that the subgrid control access in JavaScript is from CRM 2015 Update 1 onwards (which never got released for on-premise)
2) Say, even if I do this using those unsupported methods, won't it go to an indefinite loop if I try to refresh the form during on-load of the grid? When the form is refreshed the grid will load once again and fire the on-load event which will cause the form to refresh again. (Haven't tried this, but theoretically am I correct) ?
Thanks
AbD
Hi,
Its possible through code only. No other way is possible.
You will have to add JavaScript function on the OnLoad event on grid control. Refer below link:
https://msdn.microsoft.com/en-in/library/dn932126.aspx#BKMK_subgridAddOnLoad
When everytime we create child record, grid gets refreshed and on load event gets triggered.
In this function, you will have to refresh the form with below method:
https://msdn.microsoft.com/en-in/library/dn481607.aspx#BKMK_refresh
Any ideas how do I refresh the page after the child records are created? I tried, in the same workflow, update some fields of the parent record hoping that it would refresh. But it doesn't, event those changes are visible after a (manual) refresh. My CRM version 2015 so I cannot attach any events to the subgrid in a supported way either. Since the update I mentioned also doesn't show up in real time, I am unable to use on-change of any fields in the parent record as the changes doesn't show up immediately hence doesn't fire the event.
I am trying to avoid the need of writing plugin for this purpose.
Thanks
AbD
Yep. I agree. :P
André Arnaud de Cal...
291,996
Super User 2025 Season 1
Martin Dráb
230,853
Most Valuable Professional
nmaenpaa
101,156