Skip to main content
Question

API_GetUserRole | Multiple Roles

  • February 23, 2024
  • 0 replies
  • 157 views

Forum|alt.badge.img+5

Hello,

Hopefully this is simple for a jinja2 master.

I have a pipeline that is running the API_GetUserRole. 

I have everything working, except for when a user has multiple roles. When that happens, I get a blank value for role_id and role_name. I shortened the jinja2 to pull all data so I can see what is happening. Here is the jinja2 to pull everything:

{{ b.json.qdbapi.user.roles }}

Here is the output on the QuickBase record:

OrderedDict([(u'role', [OrderedDict([(u'@id', u'45'), (u'name', u'Claims - Processor (Incela/Hawaii Legacy)'), (u'access', OrderedDict([(u'@id', u'3'), ('#text', u'Basic Access')]))]), OrderedDict([(u'@id', u'55'), (u'name', u'EUTF Add/Edit'), (u'access', OrderedDict([(u'@id', u'3'), ('#text', u'Basic Access')]))])])])

This is what I hope to accomplish and see within the record:

Role_ID: 45 ; 55

Role_Name: Claims - Processor (Incela/Hawaii Legacy) ; EUTF Add/Edit

This was my last attempt at Jinja which output the value of "No roles assigned":

{% if b.json.qdbapi.user.roles %}
    {% if b.json.qdbapi.user.roles.role %}
        {{ b.json.qdbapi.user.roles.role['@id'] }}
    {% else %}
        Role ID not available
    {% endif %}
{% else %}
    No roles assigned
{% endif %}

Any ideas?



------------------------------
QuickBase Administrator2
------------------------------

This topic has been closed for replies.

Forum|alt.badge.img+9
  • Registered
  • February 23, 2024

Is it still working when you have a single user role? My suggestion would be to change up how you're trying to evaluate if its a single or multi use case by checking if the data type is a mapping. So in the case of someone who only has 1 role if you do the following: 

{{b.json.qdbapi.user.roles.role is mapping}} will return TRUE because the format is a mapping object

Where as the same check for a user with multiple roles will return FALSE because the data type is a List 



------------------------------
Chayce Duncan
------------------------------