How to redirect on button click to variable URL

Hello,

How can I edit button properties so on click it redirects me to a variable SharePoint URL, I need to ad the Current element ID to the hyperlink.

I tried this code and no luck:

fd.spRendered(function(result) {

var url = "http://intranet.maib.local/sites/help/Workflows/preluareElement/preluareElement.aspx?List={7a9edd38-3f18-4bef-99f6-062067196fa2}&ID="+fd.field('ID').value+"&ItemGuid={B0D8F867-168D-4B6E-9899-673CA5DE859E}&TemplateID={5146d5c6-d10e-4e19-b2a4-7b23e5db8e4b}&Source=http%3A%2F%2Fintranet.maib.local%2Fsites%2Fhelp%2FLists%2FCerere%20de%20suport%2FAllItems.aspx%3Fweb%3D1";

result.RedirectUrl = url;

});

Thank you.

Hello @Vasilii_Burca,

The RedirectUrl field is available only under the spSaved event. Please find more information here.

If you need a button that saves items and redirects a user to the specific URL that includes item ID, please use the following code in the button's onClick settings.

fd.spSaved(function(result) {
    var itemId = result.Id;
    result.RedirectUrl =
        "Your URL" + itemId;
});

return fd.save();

Also, you might be interested in the Redirect user after form submission in SharePoint article.

1 Like

Thank you that helped a lot and very handy by the way that it automaticly replaces ID.

After further testing, it seems like it does not change the ID portion.
I marked the portion of URL I need to change with the current Item ID
Here is my code:

fd.spSaved(function(result) {
var itemId = result.Id;
result.RedirectUrl =
    "http://intranet.maib.local/sites/help/Workflows/preluareElement/preluareElement.aspx?List={7a9edd38-3f18-4bef-99f6-062067196fa2}&***ID=72***&ItemGuid={BE628B7D-57E1-44C0-8377-A389786A17E7}&TemplateID={ed452887-7ecf-4a7b-9d9f-de7b1b8eb19e}&Source=http%3A%2F%2Fintranet%2Emaib%2Elocal%2Fsites%2Fhelp%2FLists%2FCerere%2520de%2520suport%2FAllItems%2Easpx%3Fweb%3D1" + itemId;

});

return fd.save();

And one more question can i just close the form without saving an redirect fd.close() or something like in Infopath ?

Thank you!

Hello @Vasilii_Burca,

You need to combine the string with item ID variable, please see the updated code.

fd.spSaved(function(result) {
    var itemId = result.Id;
    result.RedirectUrl =
        "http://intranet.maib.local/sites/help/Workflows/preluareElement/preluareElement.aspx?List={7a9edd38-3f18-4bef-99f6-062067196fa2}&ID=" + itemId + "72&ItemGuid={BE628B7D-57E1-44C0-8377-A389786A17E7}&TemplateID={ed452887-7ecf-4a7b-9d9f-de7b1b8eb19e}&Source=http%3A%2F%2Fintranet%2Emaib%2Elocal%2Fsites%2Fhelp%2FLists%2FCerere%2520de%2520suport%2FAllItems%2Easpx%3Fweb%3D1";
});

return fd.save();

And to redirect to specific page when the form is closed, you can use this code:

fd.spClosed(function(result) {
	fd.source="URL";
})
1 Like

Thank you very much !

1 Like

@Margo - Hello there. quick question. Newbie here. How can i make the button redirect to a URL when pressed?

Hello @EchodaPogi,

Simply add this code to the button's click property:

window.location.href = 'https://plumsail.com'

image

Thank you @Margo . It worked perfectly

1 Like