Hi folks,
I have two custom Entities related to the Contact Entity:
- Training
- Training Need
Both of these appear on the Contact Form as sub-grids. I have a plugin that runs on the Create message for the Training Entity, which checks to see whether the Training added is meeting a Training Need, and if so it deactivates the corresponding Training Need. The plugin runs fine but the Training Need sub-grid doesn't update (refresh) automatically when adding the Training.
Can anyone think of a way around this? I know that the plugin can't refresh the form and I probably can with Javascript but I'd need to somehow call the Javascript once the plugin has stopped running; or is there another way?
Thanks in advance!
Matt
*This post is locked for comments
For anyone interested in the solution I used, it's JavaScript-based:
var mySubgridOnLoadFunction= function () { Xrm.Page.getControl("subgrid2_name").refresh(); };
You would then use the addOnLoad method to call this from the first grid - i.e. when that grid refreshes it will then call your custom function:
Xrm.Page.getControl("subgrid1_name").addOnLoad(mySubgridOnLoadFunction);
It would need tweaking a bit for the new 9.0 Client APIs - not that it won't work but, you know, to be good.
Hope that all makes sense and I haven't made any mistakes, it's been a long day.
Matt
I'm not sure how I came across this given that it's Estonian(?) but here's the link I used for reference: https://docs.microsoft.com/et-ee/previous-versions/dynamicscrm-2015/crm.7/dn932126(v=crm.7)
I must apologise if someone here pointed me in the right direction, it was some time ago.
Hi Matt,
You can create a dummy field on contact, which you update from your plugin code, and on change of that field value you can call below javascript function,
function refreshsubgrid()
{
Xrm.Page.getControl("subgridName").refresh();
}
or other option is to setTimeout, on certain interval you can refresh your subgrid by below code,
function Refreshsubgrid()
{
setTimeout(Xrm.Page.getControl("subgridName").refresh(), 3000);// time is in milisecond
}
Best Regards,
Shahbaaz
Ah sorry Matt for misunderstood your question.
Actually when you create or open child record, you can get properties and event of the parent via window.opener. Then when on child event Form_OnSave, you can put javascript function to call parent's method refresh subgrid. Maybe this one will be an elegant way to do it.
Hi Matt,
Another workaround you can use here to fresh sub grid after specified interval, you can use set interval method. It should be something like this
function refreshSubgrid() {
setTimeout("refresh();", 2500);
}
function refresh() {
Xrm.Page.getControl("contactopportunitiesgrid").addOnLoad(GridOnloadFunction);
}
You can also look some options here: stuffandtacos.azurewebsites.net/.../refresh-parent-entity-when-creating-a-quick-create
Hi Temmy,
That sounds interesting, except that there are no attributes being modified on the Contact Form itself - it's the two sub-grids that are being updated. Can you use Javascript to detect additions or changes to the sub-grid records?
Thanks
Matt
Hi,
Actually when on save and plugin triggered, out of the box crm will scan all attributes that changes and execute event on those attributes. So you can actually register event on modifiedon attribute to call Xrm.Page.data.refresh or Xrm.Page.getControl("gridname").refresh ().
Hey Matt,
Plugins execute server side and you want to refresh your training grid from client side so first of all you need to have some triggering point to know when your training record added and subgrid will refresh. OOB supported way its not possible .
There is one workaround which is completely unsupported way like , let say you are in contact form , now if you open the training creation form in a popup so from popup window onsave you can get the parent window grid and on save success method you can fired the below JS to refresh the grid.
var subgrid = document.parentWindow.parent.parent.opener.Xrm.Page.ui.controls.get("GridName"); // You may need to add additional parent or remove parent. subgrid.refresh();
Hope this helps.
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,188 Super User 2024 Season 2
Martin Dráb 230,030 Most Valuable Professional
nmaenpaa 101,156