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)

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

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

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

  • MattTaylor Profile Picture
    130 on at

    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
    Mahendar Pal Profile Picture
    45,095 on at

    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

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    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
    Shahbaaz Ansari Profile Picture
    6,211 on at

    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

  • Verified answer
    MattTaylor Profile Picture
    130 on at

    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.

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