Keep recordID URL when using quick links

Hello!
First post here :wink:

My case:

  • I created a record detail page with quick links inside of it.
  • Each quick link gets you to another page with some of the previous record’s details. It is a way to organize the large amount of data related to the chosen record.

My problem:
When clicking on any of the quick links, the content is not filtered anymore on the chosen record — i am seeing a random record’s details.

I feel like i have to get the recordID passed on in the URL anytime i am using one of the quick links so that the content is always related to the chosen record.

But i do not know how to do it.

Thanks for your help!

Hi,

In the details page with quick links inside, does the recordId appears in the url parameters of this page?

If so I have the script for it (but the recordId needs to appear in the url parameter of the page where the quick links are).

If not, let me know, I can find a way to grab the right recordId

Hi Matthieu,

Yes, the recordId appears in the url of the detail page that i created.

On the contrary — as you probably guessed — the recordId is not included in the url of any quick links that are on this page.

Yep, so here is the script to be inserted in the page settings => custom code => header
The only thing you might need to change in the script is “quick-links1” (line 1 and 8). This is the id of your quick links block. If your quick-links block has the id “quick-links1” => nothing to change.

Let me know if any trouble

<script>
  window.addEventListener('block-loaded-quick-links1', () => {
    function getUrlParam(name) {
      const urlParams = new URLSearchParams(window.location.search);
      return urlParams.get(name);
    }

    const recordId = getUrlParam('recordId');

    if (recordId) {
      document.querySelectorAll('#quick-links1 a').forEach(link => {
        link.addEventListener('click', function (event) {
          event.preventDefault(); 
          event.stopPropagation();

          const url = new URL(link.href, window.location.origin);
          url.searchParams.set('recordId', recordId);

          window.location.href = url.toString();
        });
      });
    }
  });
</script>