2

I get the error :

Object doesn't support property or method 'set_formDigestHandlingEnabled'

when I try to get the current SPContext object from javascript code in an Office 365 site.

I am using a script editor web part and getting the context to do further operations

var cntxt;
.
.
.
cntxt = SP.ClientContext.get_current()

Has anyone faced this before?

6
  • 2
    Have you tried cntxt = new SP.ClientContext(currentUrl);?
    – wjervis
    Commented Jul 30, 2014 at 12:43
  • I have tried that. Doesn't work !! Commented Jul 30, 2014 at 20:19
  • Are you making the call from an app or a regular site collection on your O365 host?
    – John-M
    Commented Jul 31, 2014 at 0:55
  • Not an app. I have just placed a script editor web part on my page in an Office 365 site collection. If I try to get the "SP" and "SP.ClientContext" objects in the IE developer toolbar console, the objects are returned.. It is just the "get_current()" method that is throwing the error !! Commented Jul 31, 2014 at 9:06
  • Try removing all other custom scripts from the page, and then calling SP.ClientContext.get_current() in the console; does this happen on just this page, or others, just this site collection, or others?
    – John-M
    Commented Jul 31, 2014 at 10:30

4 Answers 4

1

Based on comments to the original question, the way in which the scripts are loaded on your page must be preventing SharePoint from initializing all of the standard JavaScript items on the page. Add your custom scripts one by one, and remember that you may need to use jQuery.ready, SP.SOD.ExecuteOrDelayUntilScriptLoaded(<yourscript>, "SP.js") // or sp.ui, or sp.core, or something else, but usually SP.js is sufficient, or some other similar technique to make sure SharePoint has initialized its environment before you load your custom script.

6

I had the same error message in a html without SharePoint Server rendering. For me I mixed up the load sequence of the sp.runtime.js and sp.js. You have to load the sp.runtime.js before the sp.js

<head>
  ...
  <script src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
  <script src="/_layouts/15/sp.runtime.js"></script>
  <script src="/_layouts/15/sp.js"></script>
  ...
</head>
1
  • this helped.....
    – Gaurravs
    Commented Jun 7, 2018 at 15:52
5

Using 'new' is definitely required, as suggested by wjervis: var context = new SP.ClientContext(currentUrl);

1
  • Adding 'new' worked for me.
    – Asad Refai
    Commented Jun 9, 2016 at 9:23
0

You need to use ExecuteOrDelayUntilScriptLoaded function :

ExecuteOrDelayUntilScriptLoaded(internalOpenDialog, "SP.JS");

function internalOpenDialog(){
......
//code
....
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.