Redirect form on Close

How do you redirect a from from a close button?

Hi!

You can use ‘spClosed’ event handler:

fd.spClosed(function() {
    window.location = "URL...";
}

Also, you can find more information about a redirection: https://plumsail.com/docs/forms/how-to/redirect-sp-save.html

When I use that fuction and use on click of return fd.close(); it does not redirect. but if I do a return fd.Closed() then the button does nothing form does not close or redirect.

Hi!

OK, please copy and paste this code:

fd.spClosed(function() {
	fd.spFormCtx.RedirectInfo.redirectUrl="http://stackoverflow.com";
}) 

It should help.

Notice that there is no ‘fd.closed()’ event, only ‘fd.spClosed()’.

That worked! Thank you

I am using

fd.spClosed(function() {
fd.spFormCtx.RedirectInfo.redirectUrl=“https://mysite.aspx”;
});

and it is now working, am I missing something?

Dear Stefanie.

Please try to use

fd.spClosed(function(result) {
	fd.source="http://stackoverflow.com";
}) 

instead.

3 Likes

Hi Alex,

I wonder, if there is an spClosed event, is there also a spBeforeClosed event?

Is it right that I cannot put an asynchronous function (such as a PnP update) in the spClosed or spSaved events? I know I can do this in beforeSave, but how to do it also in beforeClosed - if it exists?

Kind regards, Andy

Hello @abolam,

Why not? You can use something like this code below that creates a new item then the item is closed:

fd.spClosed(function() {

pnp.sp.web.lists.getByTitle("List Name").items.add({
			Title: "New Item"
		}).then(function(){
		    console.log("Created!");
		});
}); 

But it depends on what exactly you want to do. We wouldn't recommend using something like the above code, as you might create lots of extra records.

Hi Nikitina,

Sorry I thought it wasn't allowed, must be mixing it up with Forms Designer, that's great, if I can do that I should be able to achieve what I need to. Thanks!!

1 Like

Hi Nikitina, seem to be getting issues when I use a .then in my spClosed handler:

fd.spClosed(function(result){

var getThisItem = result.itemId;
pnp.sp.web.lists.getByTitle('OMC%20Approvals').items.getById(getThisItem).select('ID,Editor/Title,CurrentLoggedInUser').expand('Editor')
.then(function (currentOMC){
'do some stuff here'
});

});

When I debug this the form gets to .then and then throws me out without doing anything further. Can you advise on what might be happening there?

Hello @abolam,

fd.spClosed doesn't return any data. Please use fd.itemId to get the ID of the item.