0

Foll. is code for the function:-

 function openModalDialogDetails(Stringurl, width, height,modaltype,fieldname,empname,childfrm) {

    modaltitle="Effective Data for " + fieldname + " - " + empname ;

        options = SP.UI.$create_DialogOptions();
        if(modaltitle!="")
        {
        options.title = modaltitle;
        }
        options.width = width;
        options.height = height;
        options.url = Stringurl;

        if(childfrm !="")
        {
        options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallbackED);
        }
        else
        {
        options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
        }        
        SP.UI.ModalDialog.showModalDialog(options);

    }


    function CloseCallback(result, target) {
    if((target !=null && target !="null")|| typeof(target)=="undefined")
    {
   setTimeout(ShowLoadingImg,1);

    var docURL = document.URL;

      window.location.href=docURL;

        }
        else
        {

        }
    }


    function CloseCallbackED(result, target) {  
    setTimeout(ShowLoadingImg,1);
     var docURL = document.URL;
     window.location.href=docURL;

    }

The call to this is made as follows:-

  openModalDialogDetails('../../SitePages/Effective Data.aspx?EmpID=1&tList=Employee Information&tType=3&tField=Work Pattern&sList=Work Pattern', '650', '400', '1', 'Work Pattern', 'Nachiket Kamat', 'ED');

This was working in SP2010, is there something changed in SP2013 like the way we open modals?

Upon using debugger; I get below error:-

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method '$create_DialogOptions'

2

If that is the issue, this part

options = SP.UI.$create_DialogOptions();
    if(modaltitle!="")
    {
    options.title = modaltitle;
    }
    options.width = width;
    options.height = height;
    options.url = Stringurl;

can be rewritten to

    var options = {
        width: width,
        height: height,
        url: Stringurl
    };

    if(modaltitle!="")
    {
        options.title = modaltitle;
    }

But the risk is that SP.UI.ModalDialog.js is not loaded, so you should use

var options = {
        width: width,
        height: height,
        url: Stringurl
    };

    if(childfrm !="")
    {
    options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallbackED);
    }
    else
    {
    options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
    }

SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
  • that worked.. changing the way the var options as well as using SP.SOD.execute made it working.. But why was SP.UI.$create_DialogOptions(); a problem? and how come this and js not loading never caused issue in SP2010? – variable Mar 5 '14 at 12:46
  • 1
    It is because of SP 2013 using what's called Minimal Download Strategy (MDS) as well as lazy load of javascripts. Meaning that you must make sure that the javascripts you depend on loads before your code executes :) – Robert Lindgren Mar 5 '14 at 12:58
  • HI Robert, We have another SP2013 site, on that, there is a webpart with the similar code and it works just perfectly! ANy idea why that works well? The only difference in the SPsite where it doesnt work is that we are using AJAX CONTROL TOOLKIT. – variable Mar 6 '14 at 4:34
  • Are you sure that is the only difference? I have noticed that publishing sites tend to still work more like 2010 JavaScript wise. For example they have the MDS feature disabled – Robert Lindgren Mar 6 '14 at 5:41

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.