Save and redirect from Modal


Posted by Cloud.Ed - Dec 4 ’15 at 02:40

Is there a way to save from a Modal form and redirect to the Modal edit form?

  • rostislav
    Member for: 5 years 22 days
    #1 by rostislav Dec 7 ’15 at 07:42

    There is no good way, but here's what you can do (untested code, but should work):

    //Open your dialog like this
    	url: '/Lists/Custom/fd_Item_Edit.aspx?ID=1',
    	dialogReturnValueCallback: Function.createDelegate(null, Callback)
    //where Callback is what will be executed when the dialog is submitted
    function Callback(result, target) {
        if (result == SP.UI.DialogResult.OK) {
            //here you will need to retrieve the ID of the last submitted item in that list, where the author is the current user. See below for more info
            //once you got your id, you'll need to generate the URL and then use that url to open a dialog 
        if (result == SP.UI.DialogResult.cancel) {
            // do not do anything?


    Here is some documentation that will help you get the ID of the item: (the CSOM section)

  • Cloud.Ed
    Member for: 4 years 8 months 2 days
    #2 by Cloud.Ed Dec 7 ’15 at 04:41

    [#1]: I'm confused, sorry! We would like to create a new list item from the list in dialog. From that new item we would like to save and then open the edit form. I have code to get the latest ID created but I'm unsure how to save the new form and redirect.


    Thanks again!



  • rostislav
    Member for: 5 years 22 days
    #3 by rostislav Dec 8 ’15 at 05:16

    The message was removed by a forum moderator.

  • rostislav
    Member for: 5 years 22 days
    #4 by rostislav Dec 8 ’15 at 05:35


    Are you saying that you are opening the new item form in a dialog from the actual list, not from another form? In that case, you could add some custom JavaScript code to the actual SharePoint page via SharePoint Designer. You'd have to replace the default functionality of the New item link with a custom SP.UI.ModalDialog.showModalDialog function, as described in the answer above.


    The course of action would be:


    1. Add JavaScipt/jQuery code to the SharePoint page in SharePoint Designer


    2. The code would get the new item link, and replace the onclick property with something different


    3. Namely, with a SP.UI.ModalDialog.showModalDialog function. This function will open the new item form. The function would, besides other things, have a callback function (a function that is called when the dialog is closed).


    4. Which would itself open a different dialog, using the same SP.UI.ModalDialog.showModalDialog function. This function would open the edit form.

Displaying 1 to 4 of 4 messages