Save and redirect from Modal

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Cloud.Ed
Posts: 40
Joined: Fri Dec 04, 2015

04 Dec 2015

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

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

07 Dec 2015

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

Code: Select all

//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/librar ... 45759.aspx

http://chuvash.eu/2012/06/20/three-ways ... plistitem/ (the CSOM section)

Cloud.Ed
Posts: 40
Joined: Fri Dec 04, 2015

07 Dec 2015

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

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

08 Dec 2015

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.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests