Forum Discussion

QuickBaseAdmi10's avatar
QuickBaseAdmi10
Qrew Member
3 months ago

API_GetUserRole | Multiple Roles

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
------------------------------

4 Replies

  • 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
    ------------------------------
    • ShaneMiller1's avatar
      ShaneMiller1
      Qrew Cadet

      Hey Chayce, 

      Good to talk to you again. So I was able to find a work-around for this, but I'm down another rabbit hole with a similar issue that may be easier since you use and are familiar with this API.

      Firstly, so that I can help anyone down the road, here is the code to loop through the role id in the case there are multiple:

      {% set roles =  b.json.qdbapi.user.roles.role %}
      {% set separator = "; " %}
      
      {% for role in roles %}
        {{ role['@id'] }}
        {% if not loop.last %}{{ separator }}{% endif %}
      {% endfor %}

      This creates a wonky output, but I fixed that by adding a formula - multi-select text field with a formula of:

      Split([Role ID (Generated by Pipelines)], ";")

      Now I can easily see both Role ID's. This works for the role names as well, and keeps them in the same order as the ID's as long as you don't have a ';' within the role name of course.

      Now for my hopefully easier issue. Are you familiar with how to pull the access name and access id from the api response?



      ------------------------------
      Shane Miller
      ------------------------------
      • ChayceDuncan's avatar
        ChayceDuncan
        Qrew Captain

        How you 'use' it will ultimately depend on how you're passing it into QB but the actual task of getting to the object itself is just a matter of continuing the JSON path through to the access object. So if in the case of a single user/role you would just have json.qdbapi.user.roles.role.access["@id"] and json.qdbapi.user.roles.role.access["#text"]. 

        In the case of your loop you still do the same thing - just role.access["#text"] or role.access["@id"]



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