How to Auto Refresh A Webpart In Modern Sharepoint Page

Rashu, Rahul (AGCO) 0 Reputation points
2023-01-23T14:53:34.22+00:00

Hello Guys,

I have a modern sharepoint site. I have added a document library webpart in a page. We have a workflow that creates folders in this library. The issue is, the changes( like new folders) do not show on this webpart immediately. We refresh the page and it appears.But this is not what we want. We want a mechanism to auto refresh the webpart only without auto refreshing the page. I know there are scripts to auto refresh page but we do not want to refresh the whole page , but just the webpart.

Please let me know if there is any solution to this

Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Microsoft 365 and Office Development Microsoft 365 Publishing
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-01-24T03:04:13.93+00:00

    Hi @Rashu, Rahul (AGCO)

    In SharePoint online modern page, for security reasons, modern web parts do not allow for the insertion of code like JScript. But you could add Modern Script Editor web part by adding an app.

    1.Settings > add an app > Modern Script Editor web part by mikaelsvenson

    112448-1.png

    2.Remember allow Custom Script in Classic SharePoint admin center > setting > Custom Script

    112478-2.png

    3.Then you could add Modern Script Editor web part

    112479-3.png

    Then you could use the following JS code to refresh the webpart every 1 minute

    function refreshwebpart(){
    window.location.reload(#id);
    }
    setTimeout(refreshwebpart,60000);
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.