web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

Auto Refresh Page View using JavaScript

(0) ShareShare
ReportReport
Posted on by 35

Hello experts,

I want to refresh the Page on success of dialogue box Button click in JavaScript.

I tried to solve it  by using 

  1. parent.Xrm.Page.data.refresh(true);
  2. Xrm.Page.data.refresh(true);
  3. window.refresh();

but, all of this won't refresh the view and unselected the selected record.

so is there any way, to reload the page, or auto click the refresh button.

Here is my part of Code, where i am using refresh page function

var error = JSON.parse(this.response).error;
                Xrm.Navigation.openErrorDialog({ message: error.message}).then(
                function(success) 
                { 
                    setTimeout(function () {
                        parent.Xrm.Page.data.refresh(true);
                    }, 500);
                    
                }, 
                function (error) 
                { 
                    console.log(error); 
                    setTimeout(function () {
                        parent.Xrm.Page.data.refresh(true);
                    },800);
                    
                });
I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at
    RE: Auto Refresh Page View using JavaScript

    Hi Anubha,

    Try to fire the click event of refresh button element manually.

    parent.document.querySelectorAll('[aria-label="Refresh"]')[0].click();

    Regards,

    Clofly

  • cloflyMao Profile Picture
    25,210 on at
    RE: Auto Refresh Page View using JavaScript

    If the view you referred to is subgrid, you could try following approach.

    For example, I will refresh contact subgrid of account.

    1. Get the data attribute of ellipsis button.

    pastedimage1602832308601v1.png

    2. The first command will show the flyout menu.

    parent.document.querySelectorAll("[data-lp-id='SubGridStandard:contact-OverflowButton'")[0.click();

    pastedimage1602832381760v2.png

    When the flyout menu appears, the refresh button element will be available on document.

    It will be the second refresh button.(The first is the refresh button of ribbon.)

    parent.document.querySelectorAll('[aria-label="Refresh"')[3;

    pastedimage1602832679181v3.png

    pastedimage1602832913359v5.png

    (parent.document.querySelectorAll('[aria-label="Refresh"')[0, 1, 2 are all referred to Refresh button of ribbon.)

    3. Therefore, we combine two commands to refresh the subgrid.

    parent.document.querySelectorAll("[data-lp-id='SubGridStandard:contact-OverflowButton']")[0].click();
    parent.document.querySelectorAll('[aria-label="Refresh"]')[3].click();

    Regards,

    Clofly

  • Anubha Soni Profile Picture
    35 on at
    RE: Auto Refresh Page View using JavaScript

    thank you for your excellent response.

    I want to auto refresh the Page View of an Entity, so that selected data get unselected automatically.

    Thanks!

    Anubha Soni

  • cloflyMao Profile Picture
    25,210 on at
    RE: Auto Refresh Page View using JavaScript

    Hi Anubha,

    Could you share a screenshot of "the Page View of an Entity"?

    Regards,

    Clofly

  • Anubha Soni Profile Picture
    35 on at
    RE: Auto Refresh Page View using JavaScript

    Hi expert,

    here is my page, which i want to auto refresh.

    5023.pastedimage1603193773045v1.png

    Thank!

    Anubha Soni

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at
    RE: Auto Refresh Page View using JavaScript

    Hi Anubha,

    Thanks for sharing details.

    You can do it following two approaches:

    1. The unsupported way:

    As what I said in my first answer, fire the click event of refresh button element manually.

    parent.document.querySelectorAll('[aria-label="Refresh"]')[0].click();

    2. Supported way:

    Pass SelectedControl parameter to command of your custom button.

    pastedimage1603264049698v1.png

    Then we can refresh the view with such syntax:

     selectedControl.refresh(); 

    function test(selectedControl) {
      selectedControl.refresh(); 
    }

    Please refer to the article:

    https://nemely.com/blog/refresh-crm-grid-using-javascript/

    I tested the method and it works!

    chrome_2D00_capture.gif

    Regards,

    Clofly

  • Anubha Soni Profile Picture
    35 on at
    RE: Auto Refresh Page View using JavaScript

    Screenshot-2020_2D00_10_2D00_22-182845.pngThank you so much for your reply,

    Can you please tell me how to resolve that issue which i am facing.

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at
    RE: Auto Refresh Page View using JavaScript

    Hi Anubha,

    There are only 3 elements that have aria-label="Refresh" attribute, the start index is 0. So the range is from 0 to 2.

    pastedimage1603372612289v1.png

    Try executing parent.document.querySelectorAll('[aria-label="Refresh"]')[2].click(); to check whether it could refresh view.(I tested and it works.)

    123.gif

    Regards,

    Clofly

  • Anubha Soni Profile Picture
    35 on at
    RE: Auto Refresh Page View using JavaScript

    Thank you so so much, your help made a great change. Thank you it is working perfectly fine.

  • Anubha Soni Profile Picture
    35 on at
    RE: Auto Refresh Page View using JavaScript

    Exact and proper Solution. Thank you so much

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 58

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 16 Super User 2025 Season 2

#2
CU29080825-0 Profile Picture

CU29080825-0 16

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans