Forum Discussion
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
------------------------------
- ShaneMiller17 months agoQrew 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
------------------------------- ChayceDuncan7 months agoQrew 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
------------------------------- ShaneMiller17 months agoQrew Cadet
Awesome, that worked. It's so weird, I must have been at it too long because prior to trying to loop everything I had both the access id and access name fields populating. Then for the life of me I couldn't get it to work pre-looping. Probably a silly syntax error... 'name' instead of '#text'.
Either way, thank you! It's all working as expected now
------------------------------
Shane Miller
------------------------------