CharleneDougal1
2 years agoQrew Member
API_UserRoles
Is there a way to filter API_UserRoles based on Role ID? ------------------------------ Charlene Dougall ------------------------------
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 -%}
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!