SharePoint 2013 server...

I have created a custom aspx page for use as a modal dialog. I want this pop up to collect field values and return them to the form the pop up was called from. The pop up opens fine, but when I click 'OK' I get.... 'SP' is undefined.

Using a button, I am loading sp.js (as below) before calling my close and pass data function (which contains the error line above). Is there another SharePoint library I should be loading?

function loadScripts(){
    SP.SOD.executeOrDelayUntilScriptLoaded(closePopupAndPassData, "SP.js");

function closePopupAndPassData(){
    var fakeData = "test";
    SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, fakeData);

Thanks in advance for any feedback.

  • Try this ExecuteOrDelayUntilScriptLoaded(closePopupAndPassData, "SP.js") Commented Oct 21, 2014 at 16:09
  • 'ExecuteOrDelayUntilScriptLoaded' is undefined. :(
    – Das
    Commented Oct 21, 2014 at 16:14
  • Because I basically used a blank aspx page through the use of SharePoint Designer 2013....I feel like I'm just missing certain SP script library references....but have no idea which others to use....???
    – Das
    Commented Oct 21, 2014 at 16:16
  • 1
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { console.log("Initiating SP.ClientContext") }); SP.SOD.executeOrDelayUntilScriptLoaded(closePopupAndPassData,"sp.js"); Commented Oct 21, 2014 at 16:25
  • 'SP' is undefined on the SP.SOD lines.
    – Das
    Commented Oct 21, 2014 at 16:39

3 Answers 3


You should add following reference to your ASPX markup

<Sharepoint:ScriptLink ID="ScriptLink1" Name="sp.ui.dialog.js" LoadAfterUI="true" Localizable="false" runat="server"></Sharepoint:ScriptLink>   
<SharePoint:FormDigest runat="server" /> 
  • Added your suggestion. Before the modal dialog opens, I'm now getting "Type is undefined" on Type.registerNamespace("SP").
    – Das
    Commented Oct 21, 2014 at 17:42
  • Can you update the question and post the complete code in the aspx markup Commented Oct 21, 2014 at 17:48

In addition to loading the sp.ui.dialog.js file, change the



SP.SOD.executeFunc ("sp.js","sp.ui.modalDialog",myfunc)

There is a working solution of this issue in other topic:

This is what I used to fix this problem:

<SharePoint:ScriptLink Name="MicrosoftAjax.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.core.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.js" runat="server" Defer="True" Localizable="false"/>

I added the above ScriptLinks in this order, and defered both the MicrosoftAjax.js and SP.Core.js includes, and delayed the SP.js. The SP.js file has dependencies in the preceding includes that requires it to be delayed.

How can I use the SharePoint Javascript Object Model from a plain HTML page?

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.