Does the CSOM library have an auto-refresh? Or is there an API to pass form digest value in form?

jaja 1 Reputation point
2021-05-11T01:58:57.773+00:00

95462-capture.png

Hello. We have a script that is using CSOM and gets the site's current context. However, when left idle for around 15-20 minutes, the context would return undefined. After debugging, the error comes from the SP.ClientContext.get_current() as it already returns null and the rest of the source code will catch the error.

Is CSOM library auto-refresh? Or is there an API to pass form digest value in form?

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
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,021 Reputation points
    2021-05-12T06:22:41.453+00:00

    Hi @jaja ,

    You could try to use SP.ClientContext("https://yoursiteurl") instead of SP.ClientContext.get_current() to setup the clientContext. It may work for you.

    clientContext=SP.ClientContext("https://yoursiteurl")  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.