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