I have just started developing with Sharepoint Add-ins. I'm using the JavaScript API. Find below my code:

'use strict';

ExecuteOrDelayUntilScriptLoaded(getAllFiles, "sp.js");
//SP.SOD.executeFunc('sp.js', 'SP.ClientContext', helloWorld);
function getAllFiles() {
    try {
        var clientContext = new SP.ClientContext.get_current();
        //var oWebsite = clientContext.get_web();
    catch (e) {
        alert("Number:" + e.number + " and Description:" + e.description);
    alert("Client context retrieved");

I get both the alerts from above code. One from catch block and the latter one outside the catch block. The one generated from catch block doesn't give any error number or error descritpion. All it gives is `

"Number:undefined and description:undefined"


  • Why have you stopped using the Sp.SOD.executeFunc? It is a better method to use than ExecuteOrDelay..., especially on MDS enabled sites – Robert Lindgren Apr 21 '16 at 10:48
  • Yes, using SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getAllFiles); now. But still no success. – sidnc86 Apr 21 '16 at 11:40
  • Just for some added information, I'm running this on <tenant>.sharepoint.com/sites/<developer_site>/. In project properties, SiteUrl property has https protocol. Anything else I need to add to this piece of information? – sidnc86 Apr 21 '16 at 12:05
  • maybe it's too early to get the context at this point of time? – Gwny Apr 22 '16 at 8:05
  • If it's a addin, have you loaded the SP.Runtime.js file too? – Anders Aune Apr 22 '16 at 13:48

You have to remove the new keyword

var clientContext = new SP.ClientContext.get_current();

should be

var clientContext = SP.ClientContext.get_current();
  • Removing the new keyword didn't work for me. – sidnc86 Apr 21 '16 at 11:41
  • 1
    The exception object does not have number and description properties try to print the message property instead alert(e.message); @sidnc86 – A_Nablsi Apr 21 '16 at 15:50
  • 1
    Thanks that helped! I got a message saying "this.set_formDigestHandlingEnabled is not a function". I searched for it and got my answer on this StackExchange question: sharepoint.stackexchange.com/questions/110211/…. I had to include sp.runtime.js and that too before sp.js. Doing so prevented the exception being thrown. – sidnc86 Apr 23 '16 at 5:56
  • I too got the error this.set_formDigestHandlingEnabled is not a function. Turns out I had forgotten to add the new keyword. – rlv-dan Dec 18 '16 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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