Save and redirect from Modal

rss

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
    rostislav
    Moderator
    Member for: 4 years 3 months 12 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
    
    SP.UI.ModalDialog.showModalDialog({
    
    	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:

    https://msdn.microsoft.com/en-us/library/office/jj245759.aspx

    http://chuvash.eu/2012/06/20/three-ways-to-get-the-id-of-last-created-splistitem/ (the CSOM section)

  • Cloud.Ed
    Member
    Member for: 3 years 10 months 21 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!

     

    Rick

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 3 months 12 days
    #3 by rostislav Dec 8 ’15 at 05:16

    The message was removed by a forum moderator.

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 3 months 12 days
    #4 by rostislav Dec 8 ’15 at 05:35

    [#2]:

    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