2

The code below keeps giving an error

"Sorry, something went wrong -- an unexpected error has occurred."

I tried the same code to open an Excel workbook from another library and it worked.

The path being returned by SecCalUrl is the correct path to the calendar. I also found out it doesn't like & in the name, that's way "Cost & Billing" is separated.

function getFileName(mySection){

var webAbsUrl = _spPageContextInfo.webAbsoluteUrl;
switch (mySection){

    case 'Cost & Billing':
        var SecCalUrl = webAbsUrl + "/SitePages/Calendar_Div_Brc_Sec.aspx";
        var options = {url: SecCalUrl, width: 800, height:950, title: "Calendar"};
        SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
        break;

    default:

        var requestUri = webAbsUrl + "/_api/web/Lists/getByTitle('Organization')/Items?$filter=Section eq '" + mySection + "'&$select=SecAcron, DivAcron, BrcAcron";
        $.ajax({
            url: requestUri,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {
                if(data.d.results.length > 0) {
                    var mySecAcron = data.d.results[0].SecAcron;
                    var myBrcAcron = data.d.results[0].BrcAcron;
                    var myDivAcron = data.d.results[0].DivAcron;
                    var SecCalUrl = webAbsUrl + "/SitePages/Calendar_" + myDivAcron + "_" + myBrcAcron + "_" + mySecAcron+ ".aspx?isDlg=1";
                    var options = {url: SecCalUrl, width: 800, height:950, title: "Calendar"};
                    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);

                }
            },
            error: function (data) { alert("Failed to load your profile."); }
        });
}   

}

Edit 12/4: I did some testing with below code. It will open any URL to any list or files -- but it wouldn't open any site page URL or any external site (i.e. google).

function openDialog() {

var options = {
    url: "https://xxx.sharepoint.com/Lists/ListName",  
    //above opens list but wouldnt open https://xxx.sharepoint.com/SitePages/home.aspx or http://www.google.com
    title: "Calendar",
    allowMaximize: false,
    showClose: true,
    width: 900,
    height: 800 
};

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

Based on my testing, wiki page and Modern page are not supported in modal dialog currently.

One thread for your reference.

https://answers.microsoft.com/en-us/msoffice/forum/msoffice_sharepoint-mso_winother-mso_o365b/using-isdlg-with-pages/286f324c-3054-4d7c-8ae9-d928fd2e1b17

  • Thanks. I just left the link to open in new or current tab. – Tamras Merin Dec 7 '17 at 19:18

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.