Skip to main content
Question

API_UserRoles

  • March 22, 2023
  • 0 replies
  • 119 views

Forum|alt.badge.img+3

Is there a way to filter API_UserRoles based on Role ID?



------------------------------
Charlene Dougall
------------------------------
This topic has been closed for replies.

MarkShnierYou
Forum|alt.badge.img+24

Can you explain further what you mean?  What is your use case?



------------------------------
Mark Shnier (Your Quickbase Coach)
mark.shnier@gmail.com
------------------------------

Forum|alt.badge.img+6
  • Quickbase Staff
  • April 7, 2023

If you're using Pipelines you can use Jinja to filter the data for a specific role.  This code finds all the users with the user role of id 18 in the data in step A:

{% set users = a.json.qdbapi.users.user -%}
{% set searchRoleId = '18' -%}
{% for user in users if (user.roles.role | selectattr("@id", "eq", searchRoleId)|list|count) > 0 or user.roles.role['@id'] == searchRoleId -%}
{{ user.name }} ({{user["@id"]}}){{ "," if not loop.last }}
{% endfor -%}
  • Update 1st line with your step letter
  • Update 2nd line with role id to search for
  • The 3rd line is where the filtering happens.  Roles can either be a list or single object, so the if statement handles both of those scenarios.
  • The 4th line is where you can display the user data. In the code above it's retrieving the user name and id and displaying on a new line for each.


If you're wondering about the 3rd line syntax, the if statement needs to be added as part of the for loop so that the loop counter works correctly.

Hope that helps!



------------------------------
Doug Henning
------------------------------