0

Has anybody succesfully been able to open a dialog from a custom action on the ribbon on top of another dialog?

The use case that I have a list, which already opens in dialog. On the dispform.aspx i have a custom action in the ribbon. When I click the action an edit form from another lists open in dialog. However in does not open op top of the exsisting list, but rather replaces the existing dialog.

  • how did you create the custom action in the ribbon? – Ali Jafer Dec 18 '17 at 10:46
  • Using SharePoint designer. I would prefer not messing with the xml. – Morten K Dec 18 '17 at 10:58
0

You could add custom action to open modern dialog by JSOM.

Here is my test sample code.

<script src="https://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">

        //$(document).ready(function() {
        //    SP.SOD.executeOrDelayUntilScriptLoaded(AddCustomUserAction, "sp.js");
        //});
        //var oListItem;

        function AddCustomUserAction() {
            //Get the client context and list object
            var context = new SP.ClientContext.get_current();
            var list = context.get_web().get_lists().getByTitle("dialog");
            //Get the custom user action collection and add the user action
            var customUserAction = list.get_userCustomActions().add();
            //Set the location of the user action
            customUserAction.set_location('CommandUI.Ribbon.DisplayForm');//CommandUI.Ribbon.ListView
            //Add the properties for the custom action
            var userActionExtension = '<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">' + '<CommandUIDefinitions>' + '<CommandUIDefinition Location="Ribbon.ListForm.Display.Manage.Controls._children">' + '<Button Id="Ribbon.Documents.New.RibbonTest" ' + 'Command="CustomDialog" ' + 'Sequence="0" ' + 'Image16by16="/_layouts/images/NoteBoard_16x16.png" ' + 'Image32by32="/_layouts/images/NoteBoard_32x32.png" ' + 'Description="DialogTest" ' + 'LabelText="DialogTest" ' + 'TemplateAlias="o1"/>' + '</CommandUIDefinition>' + '</CommandUIDefinitions>' + '<CommandUIHandlers>' + '<CommandUIHandler Command="CustomDialog" ' +
            'CommandAction="javascript:SP.UI.ModalDialog.showModalDialog({ url: &#34;/SitePages/Forms/AllPages.aspx?isdlg=1&#34;, title: &#34;Custom Dialog&#34;,showClose: true });" />' + '</CommandUIHandlers>' + '</CommandUIExtension>';
            //Add the command UI extension and update the custom user action
            customUserAction.set_commandUIExtension(userActionExtension);
            customUserAction.update();
            //Load the client context and execute the batch
            context.load(list, 'UserCustomActions');
            context.executeQueryAsync(function () {
                console.log("Custom User Action added successfully to ribbon.");
            }, function (sender, args) {
                console.log(args.get_message());
            });
        }
    </script>
    <input id="Button1" onclick="AddCustomUserAction()" type="button" value="button" />

enter image description here Referenced thread.

http://www.c-sharpcorner.com/article/create-ribbon-custom-action-using-javascript-object-model-in-sharepoint-2016-and/

  • I'm having a bit of trouble getting it to work. Can I ask if your solution has been tested on SP 2016? In the console I can see, it is supposed to have loaded the custom action, but that doesn't seem to be the case. – Morten K Dec 22 '17 at 12:34
  • Oh well I figured out i can just add the javascript in the link part in SPD: javascript:SP.UI.ModalDialog.showModalDialog({ url: "MY LINK", title: "Custom Dialog",showClose: true }); Works like a charm - thanks a lot! – Morten K Dec 22 '17 at 12:59

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.