11

I got "Type is undefined" and "SP is undefined" message when I try to open the list form in sharepoint modal dialog. Could anyone help me to resolve this issue?

This is the code:

<script type="text/javascript" language="javascript" src="/_layouts/SPP.ContentDesigner/Scripts/SP.UI.Dialog.js"></script>     
<script type="text/javascript">


     //Handle the DialogCallback callback 
          function DialogCallback(dialogResult, returnValue){ 
          } 

 //Open the Dialog 
          function OpenEditDialog(id) {
              debugger;
       var options = { 
         url:"http://devcd/Lists/NewTest/EditForm.aspx?ID=1&IsDlg=1", 
         width: 700, 
         height: 700, 
         dialogReturnValueCallback: DialogCallback 
         }; 
        SP.UI.ModalDialog.showModalDialog(options); 
      }
      </script>
Bart
  • 1,027
  • 1
  • 11
  • 27
Rasu
  • 161
  • 1
  • 3
  • 7
  • In which context this js code run? web part page, or application page, or other? – Sergei Sergeev Dec 21 '11 at 17:37
  • refer answer from this, it may be helpful. – Sergei Sergeev Dec 21 '11 at 17:43
  • i got this error in sharepoint application page, my actual requirement is it should work on all type of pages(webpart page, application page, publishing page). could you guide me please? – Rasu Dec 22 '11 at 06:09
  • Hm, it works on application page for me, why do you include this script - src="/_layouts/SPP.ContentDesigner/Scripts/SP.UI.Dialog.js"? Try to rename it, may be some conflicts with standard file occure. – Sergei Sergeev Dec 22 '11 at 08:23
  • if i comment this line itself i got the same issue, do you have any idea? – Rasu Dec 22 '11 at 14:10

4 Answers4

10

SP.js uses "lazy load". Invoke your function inside ExecuteOrDelayUntilScriptLoaded:

ExecuteOrDelayUntilScriptLoaded(OpenEditDialog, "SP.js")
Anatoly Mironov
  • 5,750
  • 2
  • 29
  • 56
8

I suggest get rid of the first script reference...

<script type="text/javascript" language="javascript" src="/_layouts/SPP.ContentDesigner/Scripts/SP.UI.Dialog.js"></script>

...and load the scripts by page or master page server controls. Then control the error situation in your component code like http://microsoft-techies.blogspot.com/2014/05/script5007-unable-to-get-property.html.

Code sample:

try {
    SP.UI.ModalDialog.showModalDialog(options);
}
catch (error) {
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}
nilsandrey
  • 303
  • 3
  • 11
2

I battled with this for a good while - in my case changing "LoadAfterUI" attribute in the ScriptLink to "true" fixed it where nothing else worked.

Poolio
  • 21
  • 1
-2

You can fix this issue by using a generic object for option instead of the DialogOptions class. that mean you have to write option like this:

//Using a generic object.
var options = {
    title: "My Dialog Title",
    width: 400,
    height: 600,
    url: "/_layouts/DialogPage.aspx" };

for more information about using it, visit: http://msdn.microsoft.com/en-us/library/ff410058%28v=office.14%29.aspx and see the example.

  • The code above is already using a generic object... The issue is that the code after (SP.UI.ModalDialog.showModalDialog) is executed before SP.js is loaded – Robert Lindgren Nov 12 '13 at 16:34