Retrieving roles array of user

Dear community

How am I able to get all the roles that the logged-in user has?
I tried it with the following line in the xlsxForm, but I never get any results.

@diana or @mrjones would any of you maybe be able to answer my question above? >< I’d highly appreciate it.

Thank you very much in advance for your help
Bests,
Ünsal

Hi Ünsal, sorry for the slow response over the holidays. I haven’t had a chance to test this hypothesis out, but it is possible that you can’t directly assign the role array to a string. Have you tried assigning it to a different field type, such as a repeat group to get the inner value(s) that way? That may work, and if not perhaps someone else has encountered this situation before and could offer advice.

Hi @uensal

Currently, I don’t think there is no way to access user roles in forms. You do, however, have access to the user’s associated contact.

We had a similar request some time ago, that resulted in adding an API to verify the permissions of the logged in user - this new api is available in tasks, targets and contact-summary, and will be available in the purge function in the future (this improvement is already scheduled). For more details, please check this issue: Ability to access "user permissions" from tasks, targets, and contact-summary · Issue #6914 · medic/cht-core · GitHub

We could make this available in forms by adding another xpath extension function for the APIs (details about CHT xPath functions: app | Community Health Toolkit).

2 Likes

Hi @diana and @marc

Thank you for your responses.
I am currently not working anymore for the project and have already handed it over to my successor. If he wants to follow up on this, I think he will come forward and continue here.

Nevertheless, thank you very much for your support.
Bests,
Ünsal

Hi,
How could I access user’s associated contact in a contact form ? I’ve tried with a group contact into the user group but it doesn’t work for me, is the correct way ?