0

I'm building a SharePoint 2013, SharePoint Hosted app project using the JSOM api. I have to make use of the SP.UI.ModalDialog to popup some content in the app. I have used the getScript method to load the sp.js, sp.runtime.js and SP.RequestExecutor.js. I also have the necessary Microsoft SP js(MicrosoftAjax.js) and other jQuery files referenced in my app. Even after loading these files, when I call the method to show a simple popup on the screen I get a JavaScript error saying :

Error: Unable to get property 'execute' of undefined or null reference.

Following is the code i have used in the app.

$(document).ready(function () {


    var scriptbase = HOST_WEB_URL + '/_layouts/15/';
    $.getScript(scriptbase + 'SP.Runtime.js',
        function () {
            $.getScript(scriptbase + 'SP.js',
                function () { $.getScript(scriptbase + 'SP.RequestExecutor.js', openDialog); }
            );
        }
    );

});

function openDialog() {
    var options = {
        url: "/_layouts/15/accessdenied.aspx?IsDlg=1",
        title: 'Sharing  Information',
        width: 500,
        height: 200,
        allowMaximize: false,
        showClose: true
    };

    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);

    return false;

}

The error comes up with the SP.SOD.execute().

Has anyone faced this issue before? Can anyone help me correct this?

Thanks in advance

1
  • Are you able to get it work ? I don't know why microsoft make it so difficult.
    – user30333
    Jul 8, 2014 at 2:55

2 Answers 2

1

The web page that hosts your app must have the following:

<WebPartPages:AllowFraming ID="AllowFraming1" runat="server" />

You can try the following code from a client app part:

function ShowSharingInformation() {

    var options = {
        url: "/_layouts/15/aclinv.aspx",
        tite: 'Sharing  Information',
        allowMaximize: false,
        showClose: true,
        width: 430,
        height: 230
    };

    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
    return false;

}

OR you can try:

ShowModalDialog from Sharepoint hosted app not working

1
  • I have <WebPartPages:AllowFraming ID="AllowFraming1" runat="server" /> already in my app part page. Jun 18, 2014 at 9:46
1

Don't pass in options as an array, pass them in as individual parameters.

While, according to this reference, it says to pass it as an object array, a comment at the bottom states that is fails when executed this way.

7
  • I think what is happening is that when you pass all the parameters in seperatly, it puts them into an object array in the function itself? I don't know, just a guess.
    – Brandon C.
    Jun 18, 2014 at 9:49
  • You mean like so - SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', url,title,width,height,allowMaximize,showClose); Jun 18, 2014 at 9:56
  • Yeah, or pass them by their values as well. so it could be "/_layouts/15/accessdenied.aspx?IsDlg=1",'Sharing Information', 500, and so on.
    – Brandon C.
    Jun 18, 2014 at 10:19
  • I tried it both ways but no change. Jun 18, 2014 at 10:29
  • Are you sure you added it to the web code correctly? The error is saying that one or more parts of the execute method is null, or undefined. Which means it hasn't been created yet. Make sure this script will wait for all value, including the scripts, to be loaded before the script executes.
    – Brandon C.
    Jun 18, 2014 at 10:55

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.