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?

Microsoft 365 and Office | SharePoint | Development
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,126 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.


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.