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.
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:
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
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
});
});
Replace the view and field keys with the ones in your own app.
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?
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.