Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Refreshing sub-grid on a Form when a Plugin updates the record

Posted on by 130

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

  • Verified answer
    MattTaylor Profile Picture
    MattTaylor 130 on at
    RE: Refreshing sub-grid on a Form when a Plugin updates the record

    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.

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,203 on at
    RE: Refreshing sub-grid on a Form when a Plugin updates the record

    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

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: Refreshing sub-grid on a Form when a Plugin updates the record

    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.

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,089 on at
    RE: Refreshing sub-grid on a Form when a Plugin updates the record

    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

  • MattTaylor Profile Picture
    MattTaylor 130 on at
    RE: Refreshing sub-grid on a Form when a Plugin updates the record

    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

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: Refreshing sub-grid on a Form when a Plugin updates the record

    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 ().

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Refreshing sub-grid on a Form when a Plugin updates the record

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,188 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,030 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans