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) {
       var options = { 
         width: 700, 
         height: 700, 
         dialogReturnValueCallback: DialogCallback 
  • 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 6: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 8:23
  • if i comment this line itself i got the same issue, do you have any idea? – Rasu Dec 22 '11 at 14:10

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

ExecuteOrDelayUntilScriptLoaded(OpenEditDialog, "SP.js")
| improve this answer | |

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 {
catch (error) {
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
| improve this answer | |
  • this approach is more promising. – Shawn Sep 24 '14 at 5:54

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.

| improve this answer | |
  • 1
    As you can see in the question, the scripts are not loaded with the ScriptLink control, so this does not really apply – Robert Lindgren May 17 '13 at 13:15

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.

| improve this answer | |
  • 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

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.