6

I need to make sure sp.js is loaded before I call several functions. I currently call them as follows in SP 2013. It works, but I suspect there is a better/more efficient way.

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getCurrUser);
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', evalGroups);
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getDeptMgrs);
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getItemOwner);
12

I normally follow as below

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', readyFunction);

function readyFunction() {
    getCurrUser();
    evalGroups();
    getDeptMgrs();
    getItemOwner();
}

Its more readable!

0

For some reason, SP.SOD.executeFunc does not work for me in my SP 2010 environment (I also can't RegisterSOD), but this works nicely. I like the cleanliness of Amal's answer):

ExecuteOrDelayUntilScriptLoaded(readyFunction, "sp.js");

function readyFunction() {
    retrieveWebSite();
    runCode();
    other();
}

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.