Page 1 of 1

Redirect to Display Form after Saving (the generic way)

Posted: 21 Jun 2018
by ragesoft
Hi,

is it possible to build some generic function for the redirect to the display form after editing an element?

Something like in documentation:

Code: Select all

fd.setUrlParam(window.location.href, 'FDRedirectWithID', 'fd_Item_Edit.aspx?ID=');
But here it has the "fd_Item_Edit.aspx". How to build it to be dynamicly to the content type (e.g. "fd_Contact_Display", "fd_Request_Display.aspx").

Or maybe it is possible to place a string inside the "general" option for the form, redirecting to the display form.

Right now i've build this:

Code: Select all

fd.onsubmit(function() {
	fd.sourceFormParam(document.referrer);
	return true;
});
But this only works good in edit-form, to redirect to display form.
If i us this code in new-form, i'll receive an error...

Re: Redirect to Display Form after Saving (the generic way)

Posted: 21 Jun 2018
by Nikita Kurguzov
Dear ragesoft,
Regarding dynamic form - only if you can get the name of the content type to construct the name of the form. You can add Content Type field on the form, hide it by setting its Style to:

Code: Select all

display:none;
And then using the following code to get its text value:

Code: Select all

fd.field('ContentType').control()._el().find("option:selected").text();
Regarding the second option, with document.referrer - I do not recommend using it, and as you've noticed it doesn't work at all with the New Form. I actually don't think it will work if you open the Edit Form directly from the List View either.

Re: Redirect to Display Form after Saving (the generic way)

Posted: 25 Jun 2018
by ragesoft
Thx for the tipp.

I've now build this one:

Code: Select all

	fd.onsubmit(function() {
		var uri = _spPageContextInfo.webAbsoluteUrl + listName + displayForm;
		if(fd._formType() == "Edit"){
			uri = fd.setUrlParam(uri, 'ID', fd.getUrlParam(window.location.href, 'ID'));
		}else{
			uri = fd.setUrlParam(uri, 'FDRedirectWithID', displayForm + '?ID=');
		}
		fd.sourceFormParam(uri);
		return true;
	});
So on "New" form the "FDRedircetWithID" is used, on Edit-Form the current Item id is used.
I've placed a button in the display form to add related items in a dialog:

Code: Select all

// open target form and set parent parameter
fd.openFormInDialog(webUrl + listNewForm,{"OMSParent":parentId},function(){});
If i click the button i recive an error like

Code: Select all

"Something went wrong"
"cant find item under 'https://myportal.de/sites/admin/Lists/Networkinterfaces/fd_OMSNetworkInterface_New.aspx?IsDlg=1&FDSource=https://myportal.de/sites/admin/Lists/Systems/fd_OMSSystem_Display.aspx?ID=42&Source=https://myportal.de/sites/admin/Lists/Systems/fd_OMSSystem_Display.aspx?ID=42&ID=42&OMSParent=42&IsDlg=1' "
the problem is related to the "&ID=42" parameter, added to the url call.
Where dos it come from?
If i add the "ID" as popup parameter to the dialog options, it works, because the "ID" param is set to nothing.

Code: Select all

{"OMSParent":parentId,ID:''}
it seems, the opendialog adds all available parameters from parent to the dialog...

Re: Redirect to Display Form after Saving (the generic way)

Posted: 26 Jun 2018
by Nikita Kurguzov
Dear Ragesoft,
Can you please show me the rest of the code here?

Code: Select all

// open target form and set parent parameter
fd.openFormInDialog(webUrl + listNewForm,{"OMSParent":parentId},function(){});
Just want to know how you get these values, so I can test it myself.

Re: Redirect to Display Form after Saving (the generic way)

Posted: 27 Jun 2018
by ragesoft
Here the full code for the "onclick" event of button:

Code: Select all

var parentId = fd.getUrlParam(window.location.href, 'ID');
var webUrl = _spPageContextInfo.webServerRelativeUrl;
var listNewForm = "/Lists/Drives/fd_Drive_New.aspx";

if(fd._formType() == "New" || parentId == ""){
	parentId = fd._tempParentId();
}

// open target form and set parent parameter
fd.openFormInDialog(webUrl + listNewForm,{"OMSParent":parentId},function(){});

i "fixed" it with this code in the "onsubmit" funciton of the form:

Code: Select all

var displayForm = "fd_System_Display.aspx";
var listName = "/Lists/Systems/";
	fd.onsubmit(function() {
		var source = fd.getUrlParam(window.location.href, 'Source');
		var list = fd.getUrlParam(window.location.href, 'List');
		var uri = _spPageContextInfo.webAbsoluteUrl + listName + displayForm;
		uri = fd.setUrlParam(uri, 'Source', source);
		uri = fd.setUrlParam(uri, 'List', list);
	
		if(fd._formType() == "Edit"){
			uri = fd.setUrlParam(uri, 'ID', fd.getUrlParam(window.location.href, 'ID'));
		}else{
			uri = fd.setUrlParam(uri, 'FDRedirectWithID', displayForm + '?Source=' + source + '&List=' + list + '&ID=');
		}
		fd.sourceFormParam(uri);
		return true;
	});
	
It seems, the additional "List" and "Source" parameter in the url fixing the problem...