How we get the sourceURL in a form (to go to correct list-view back)

We open different forms basend on button links in SPO list views (generated by SPO colum formatting in modern list view). But for going back, we need the sourceUrl of the formerly list-view to show the same list-view after editing some list item.

document.referrer or instead js objects doesn't show the formerly url.



Hello @mozilla0,

You have two options to set the Source URL.

  1. Specify the Source URL in the button link in the list view.
    So the link to the item will be:
    /ListName/Item/NewForm.aspx?source=

  2. You can add the following code to the form in JavaScript Editor. But in this case, a user always will be redirected to the specified URL.

fd.saved(() => {
   result.RedirectUrl = "List view URL";
});

Hi mozilla0.

I like the look of your column formatting in modern sharepoint lists. Would you mind sharing the JSON for each of the formatted columns shown in your screencapture?

Thanks,
Stormanh

Hi @Margo, that doesn't solve my use case. I want get back to the original url which has the form loaded (like document.referrer / window.history.go(-1)), but I doesnt have a chance to get this value in the form to redierct back after save. Beacuse the form always go back to the standard view on the list.

There is no chance to retrieve the referrer url in Plumsail forms?

Hi @stormanh. Here are the files which we use for formatting the list:

DueDate.json (309 Bytes)
DMAIC.json (663 Bytes)
OnTrade.json (453 Bytes)
Button2.json (887 Bytes)
Button.json (581 Bytes)

@mozilla0,

Please use the below code to be redirected o the previous page.

fd.saved(() => {
    window.history.back();
});

Thank you very much!

Hi @Margo this code works great in SharePoint form, but when new attachments are added, they are attached to the list item. When we remove this code then attachment upload works. Any suggestions?

Thanks.

Hello @aseem,

Do you mean that you can't attach file to the list item when using this code?

fd.saved(() => {
    window.history.back();
});

If so, please check the browser console for the errors and share the screenshot.

Here is when the code is not on the form:

After the code is added:

@aseem,

I'm sorry, but I need errors from the Developer Tools → Console. Please find the instruction on how to save console logs here:

Log1713821161335.log (11.6 KB)

Hi @Margo

I have attached the log file for your review.

Thanks.

@aseem,

Thank you! Please use this code:

fd.saved(() => {
    window.history.back();
});

Thanks @Margo this worked for me:

fd.spSaved(function(result) {

result.RedirectUrl = window.history.back();

});

Hi, is it possible to execute this on close, I tried below but it does not work:

fd.spClosed(function() {
window.history.back();
});

Hello @aseem,

What specific behavior are you trying to achieve?

By default, users should automatically be redirected to the previous page when they close a form. Is that not working properly on your forms right now?

When users apply column filters, open an item for editing, and then click Close, they are returned to the view; however, all applied filters are cleared. Users would like the filters to be retained so they can continue working from the same filtered view without having to reapply them.

Hello @aseem,

Thank you for sharing this! This is actually a bug we've been working on, and we will release a fix soon. I'll post an update here once it is available.