Follow URL with multiple filters applied

Hi,

I have a page with a grid view for a logged in agency (table).
this grid view displays for a logged in agency (table) for everyone of its consultants (table) a selection of matching jobs (table)

The behavior I would like to get is that once you click on the job, you go to the specific job page AND the consultant filled in, in the drop-down. It is easy to get the job, however, I can’t find a way to also have the consultant filled in. As you can see, it goes to the right job. Without any consultant filled in by default.

For reference, here you can find the relevant table diagram:

Hi @Team, unfortunately you can only link the form to one connection value, but you can use some JS to also add on a URL variable with the row’s Consultant.

In the below method, I update each link in the Roles field by adding on a URL variable containing the row’s Consultant record ID, which passes to the form on the linked page:
url-variable

Requirements

  • Your grid of Consultants (view_xx)
  • A Jobs many-many connection field on the Consultants table (field_xx)
  • A Consultant connection field on the Agency Application table (field_yy)
  • A form to add a Agency Application to the page’s Job (view_yy)

Solution

  1. Insert the following code into your Knack JS section.
$(document).on('knack-view-render.view_xx', function(event, view, record) { //scene_66

  // Initialise constants
  const rolesField = 'field_xx';
  const applicantUserField = 'field_yy';
  const applicationViewKey = 'view_yy';
  
  // For each link in the Consultants > Jobs field
  $(`#${view.key} td.${rolesField} a`).each(function() {

    url = $(this).prop('href'); // Get the current URL in the link
    const userId = $(this).closest('tr').prop('id'); // Get the row's record ID
    // Build the URL variable object
    const object = {
      [applicantUserField]: [userId]
    }
    const json = JSON.stringify(object); // Convert the object to a JSON string
    const variableUrl = encodeURIComponent(json); // Encode the JSON string to be URL friendly
    newUrl = `${url}?${applicationViewKey}_vars=${variableUrl}` // Append to the existing URL
    $(this).prop('href',newUrl); // Update the URL

  });

});
  1. Replace the view and field keys with the ones in your own app.

Let me know how that works for you!

@StephenChapman I 100% appreciate your rigourous feedback!
I’ll keep you posted on the progress.

1 Like

@StephenChapman I’m unfortunately not getting there.

Showing you everything:

JS Code:

Your help is much appreciated.

@Team, it looks like you’ve done everything correctly.
A couple of things to check:

  1. Can you right-click and copy to here one of the Roles links in your Jobs grid to see if it’s the correct output?
    It should look something like:
https://domain.knack.com/app#jobs/job-details/664bc24d30ab65002910e51g?view_101_vars=%7B%22field_167%22%3A%5B%22664bc1b7198efb0038f7d187%22%5D%7D
  1. If you right-click the page and click Inspect (Chrome or Edge), and navigate to the Console tab in the Developer console, do you see any red error messages?
    image
    image

Hi @StephenChapman ,

  1. If i right click on the job in the grid, and copy the Link Address, I get the following: https://staffit.knack.com/staffit#agency-login/job-details6/664661581118f5002743b87f Which does not seem right.

  2. No errors to see