0

My problem is that when I start my app for the first time,it shows me an error. The error is: Unable to get property 'STS' undefined or null reference. If I refresh my app then the error disappears.

I'm working with showWaitScreenWithNoClose() from sp.ui.dialog.js. This is my code in my document.ready:

loadScreen = SP.UI.ModalDialog.showWaitScreenWithNoClose("Loading","");

and yes I've added these scripts to my master-page:

<script type="text/javascript" src="/_layouts/15/sp.ui.dialog.js"></script>
<script type="text/javascript" src="/_layouts/15/ScriptResx.ashx?    culture=en%2Dus&name=SP%2ERes"></script>

So now is my question why do I get that error and how can I solve this? I'm using IE10 maybe that could be the problem.

1
  • 1
    You do not only need to load the files, you need to make sure thay have been completely loaded before calling functions in them! Does your code work if you run it from the browsers console after the page has been loaded the first time? If it does, look in to SP.SOD.executeFunc Mar 25, 2014 at 8:57

4 Answers 4

2

The usage of jQuery document.ready in SharePoint isn't enough to guarantee that the page has been fully loaded.

In place of the document.ready function, it's suggested that you use the native _spBodyOnLoadFunctionNames array, like in the following code snippet:

_spBodyOnLoadFunctionNames.push("callMeWhenReady");

function callMeWhenReady(){
   // your code here
}

If your code depends on any of the functions within the SP.js file (or any other SharePoint file for the matter), then there is an additional function SP.SOD.executeFunc(key, functionName, fn), to be used like this:

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

function callMeWhenReady(){

}
0

I had the same problem with SP 2013.

using SP.SOD.executeFunc didn't work for me.

SP.SOD.executeFunc('sp.ui.js', 'SP.UI.ModalDialog.showWaitScreenWithNoClose', function()
{
    var modal = SP.UI.ModalDialog.showWaitScreenWithNoClose("Loading...");
    ...
});

I randomly got Unable to get property 'STS' undefined or null reference.

turns out that SP.UI.ModalDialog.showWaitScreenWithNoClose depends also on 'string.js', so I ended-up using SP.SOD.loadMultiple.

SP.SOD.loadMultiple(['strings.js', 'sp.ui.dialog.js'], function(){
    var modal = SP.UI.ModalDialog.showWaitScreenWithNoClose("Loading...");
    ...
});
0

SharePoint 2013, Provider hosted app, On-Premise Server, have the same error. Helping: SP.SOD.loadMultiple(['strings.js', 'sp.ui.dialog.js'], function(){...

With one small clarification:

strings.js located in /_layouts/15/1033/ instead of /_layouts/15/.

Now all works as needed!

0
SP.SOD.loadMultiple(['strings.js', 'sp.ui.dialog.js'], function(){
   var modalDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Please wait...', 
                   'We are loading data for you...', 100, 450);        
});

SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK);

Your Answer

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

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