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

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,071 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,767 questions
SharePoint Workflow
SharePoint Workflow
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Workflow: An orchestrated and repeatable pattern of business activity, enabling data transformation, service provision, and information retrieval.
540 questions
Microsoft 365 Publishing
Microsoft 365 Publishing
Microsoft 365: Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line. Publishing: The process of preparing, producing, and releasing content for distribution or sale.
603 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,726 Reputation points Microsoft Vendor
    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.