Block specific users from processing a connected form

I have a RAMS (Risk Assessment) process that i need to be processed by a Lead Engineer (account) who has been assigned to a works order connected field.

The RAMS form creates a Make process and puts a document in the Lead Engineers email inbox by simply processing a form.

The RAMS record is linked to the Works Order table.

What i want to know is it possible to stop the form for the RAMS being run by anyone else other than the Lead Engineer who has been associated to that page.

I may just need to create a new table for accounts that are assigned as lead engineers on a new page but i’d like to keep it all on one main works order page.

Hi @AndrewClar42169, you could keep all this on one page using Page Rules, where you can hide the particular view if the logged-in user’s role does not contain ‘Lead Engineer’.

Unfortunately that won’t work. I use page views already which is great for when using global account roles.

This field is variable, the lead engineer is set when the job is created, the engineers group can have any individual as a lead engineer, so for a specific job we only want the assigned lead engineer to have the ability to use that form.

Ah I see. Unfortunately there’s no native way to control that, so it would require a simple slice of JavaScript which will get the current logged in user from a details view, and compare it to the ‘assigned to’ field in the job/project record to hide the form view.

  1. Create a details view (e.g. view_4) with the assigned to field (e.g. field_12) visible, and the form below (e.g. view_5) that you’d like to show/hide.
    image

  2. Add the following bit of code, making sure to replace view_4 with your details view, field_12 with your ‘assigned to’ field, and view_5 with your show/hide form view.

$(document).on('knack-view-render.view_4', function(event, view, record) {
  var assignedUser = record.field_12_raw[0].id
  var loggedInUser = Knack.getUserAttributes().id;
  if (assignedUser != loggedInUser) { // Hide work order form when user is not assignee
    $('#view_5').hide();
  }
});

Hi Stephen, thank you for your contribution! Could you please share an updated version of this example that accomodates more than one (many) assigned users?

For example, if the assignedUser field was a Connection to Many users… And (3) three Users are assigned to the record… How can we verify that the loggedInUser is one of the three assigned to the review (and therefore allowed to view it)?

Basically, can this be updated to accomodate a one to many connection for the assigned users?

Thank you, @StephenChapman!

1 Like

@LowCode Wow, can’t believe I wrote this solution over a year ago!

Great question. This updated code should work regardless of whether it’s a single or multi connection by checking there’s at least one match in the connection array:

$(document).on('knack-view-render.view_4', function(event, view, record) {
  var assignees = record.field_12_raw;
  var loggedInUser = Knack.getUserAttributes().id;
  if (!assignees.some(assignee => assignee.id === loggedInUser)) { // Hide form when user does not contain assignee
    $('#view_5').hide();
  }
});

Let me know if that works for you!

1 Like

This works. Thank you, @StephenChapman! I remain hopeful that Knack will update the Builder Page Rules to enable this check (i.e., add ‘logged-in user’ to the availale selections). That would be more secure.

I very much appreciate your assistance with this. Thank you again for your valuable contributions to the Knack community.

1 Like