SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have tried this

    <script type="text/javascript">
       function myfunc()
       { ExecuteOrDelayUntilScriptLoaded(GetSuppliers, "Directory.js"); };

As suggest on another thread but this does not work. If I use a link and specify javascript:functionname(); then it works.

Anyone have any ideas? Matt

share|improve this question
looks like correct code. But what is the context? What page? – gandjustas Jul 6 '12 at 19:53
Just a standard Web Part Page – Mattmoo Jul 6 '12 at 20:00
Even added the code as a script in a Content Editor Web part and it is still not firing – Mattmoo Jul 6 '12 at 20:00
OK after debugging it seems there is a problem with my javascript, myContext = new SP.ClientContext.get_current() seems to be undefined yet when I click the link it works fine. – Mattmoo Jul 6 '12 at 20:09

The issue you are facing is that the sp.js (which holds the functions for the JavaScript Client Object Model) is not getting loaded before you call your function. It works when you click the link because the file is loaded before you click the link. We need to ensure that sp.js is loaded before you call GetSuppliers.

For that, we need to create a script dependency of the Directory.js on the sp.js. The RegisterSodDep will ensure that sp.js will be loaded before Directory.js.

Try this code:

   <script type="text/javascript">
       function myfunc()
            ExecuteOrDelayUntilScriptLoaded(GetSuppliers, "Directory.js");
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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