I have a Custom Tool part on my web part that handles properties. It has a link that when clicked shows up a modal dialog but I'm getting this error:

TypeError: SP.UI.$create_DialogOptions is not a function

this is the code called by the link:

function Initi() {

var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url = '/_layouts/MyWebPart/ModalDialog.aspx';
dialogOptions.title = "My Web Part";
dialogOptions.width = 660;
dialogOptions.height = 400;
dialogOptions.dialogReturnValueCallback = function (res, retVal) {
    if (res === SP.UI.DialogResult.OK) {
        ExecuteOrDelayUntilScriptLoaded(function () { RTEActions(retVal) }, "sp.ui.rte.js")

return false;

It used to work, but I have deleted some web parts from the page and now it's giving this error.


You have to add ExecuteOrDelayUntilScriptLoaded(Initi, "SP.JS"); before declaring function Initi

This is because SharePoint uses an on Demand Script Loading model. When the page is being loaded, the javascript remains loading. So if you are trying to create the dialog you will get that error.

| improve this answer | |
  • this will call Initi right? Just because I want to call the function by clicking a link – nhenrique Oct 1 '13 at 10:50
  • No. It just schedules an asynchronous callback function (Initi) which will be called when the script has signaled finished loading. – Alvmad Oct 1 '13 at 11:51

found it! just put this on your code

$(document).ready(function () {
    LoadSodByKey("sp.js", function () {});

reference: dotnetmirror

| improve this answer | |

You can fix this issue by using a generic object for option instead of the DialogOptions class. 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 | |

I was try with the first options but not work and found this option

I have seen on https://www.solutions2share.net/en/blog/2013/05/sp-ui-modaldialog-showmodaldialog-do-not-work-under-sharepoint-2013/

function ShowServerInformation(featureId) {
       var options = {
         url: '/_admin/Solutions2Share/LicenseManagement/ServerInformation.aspx? 
           featureId=' + featureId + "&IsDlg=1",
           title: 'Server Information',
           allowMaximize: false,
           showClose: true,
           width: 430,
           height: 230

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

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.