Selecting from a Predefined list of roles

Does anyone have a way of filtering the Roles, in Knack it is all or nothing and there are times when I just want a user to be able to add or delete from a predefined list of Roles.

I currently use a piece of Java (see below) that was given to me (I am Java illiterate) and it has worked well but unfortunately I have just found out that it allows for a search (as apposed to selecting from the list) to reveal previously hidden Roles.

It would also be much more useful if I could select roles for the Predefined List as apposed to how it is now where I have to define what Roles need to be excluded.

Any help would be gratefully received.

John

$(document).on(‘mousedown keyup’, ‘#view_3425_field_629_chzn’, function () {

var found = $('ul.chzn-results').find('li');
if (found.length > 0) {
    found.each(function () {
        var role = $(this)[0].innerHTML;
        role = role.replace('<em>', '');
        role = role.replace('</em>', '');
     if (role === 'Developer'
            || role === 'Admin2'
            || role === 'Admin3
        )
          $(this).first().removeClass('active-result');
    })
}

});

Hi

The approach I generally take when I want a user to be able to affect a role like this is to use a multiple choice field and then use record rules to actually set the user role. This way you can offer any choices you want.

Julian

Thanks for the quick reply Julian

I seem to remember trying this and not being able to make it work, cant quite remember why, I will revisit it and revert.

Hi Julian, ahh yes its all coming back to me :).

If I create a Multiple Choice field and populate it with the roles I have in “User Roles” for all users, then use Page rules to make “User Roles” = “New Multiple Field” that would work but there is no way of hiding just some “New Multiple Field” options, so all options would be visible to the user which defeats my initial object of only showing and allowing a user to add/remove predefined roles.

If I have missed something here please let me know.

Thanks for your efforts.

John

Hi

You have two options here…

  1. If you take the suggestion of using a Multiple Choice field then only add items into the list that you want people to be able to select. The use Record Rules to populate the actual User Role.
  2. If you need more flexibility to filter the list of options then set up an Object as a lookup table with whatever additional fields you need to filter the list for users. Then again use record rules to set the value.

One thing you should be aware of is that this approach will not deal with cases where users need to be assigned multiple user roles. In general Multiple Choice and Many to Many connection fields can have values added or removed from them in record rules but the User Roles field does not support this for some reason (and was the first field I tried to use add / remove with of course).

If you do need to cater for this, all is not los because you can do it with Integromat.

1 Like

Hi Julian, thanks for taking the time with this, I specifically needed the ability to add a role to existing roles in a controlled environment, unfortunately this approach doesn’t allow for that and I have found nothing that will although I have yet to look at Integromat

Hi

OK - Integromat can do that but it is not necessarily a day 1 new user type of ‘Scenario’ to create (although not that hard. This is basically because the Knack module in Integromat needs the list of roles to be set in an Array - feel free to book a Zoom with me if you would like me to show you how: