Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
What I wanted was to greet the user and wish them good morning. And that's how it all started.
A few days ago, I ran into a classic Qlik challenge: ¡Show the real name of the user currently logged into the app, using the value returned by OSUser()! Easy...maybe.
I had already had experience in getting users in PowerApps,
I assumed this would be similar, well... almost. ...
In QLik Cloud under ActiveDirectory scenario we use the OSUser() function in Qlik Cloud, we usually get something like:
userDirectory=qlikcloud;userId=xxxxxttttxxxxxx
Thanks to our partner, he saw that userid does not work, using the Qlik API, the data related to the Active Directory code is "subject". Who would have thought!
Applying SubField(OSUser(), '=', -1), we isolate only the last part: xxxxxttttxxxxxx.
This code matches the subject field in the USERS table, which is retrieved from the Qlik API and contains the user details (name, email, id AND subject, and others that we do not need to mention).
The solution (dashboard-only, dont use it in script because in script is dont dinamic, just only when reload data is called):
The USERS table loaded in our data model, we can add a text object or KPI with this expression for example:
='Hola ' & Only({< subject = {"$(=SubField(OSUser(), '=', -1))"}>} name)
You can also reapply subfield and ' ' -1 to isolate the first word before a space (Sorry Ana María, from now on it'll just be Ana 😉 )
This is useful not just in dashboards to give users a sense of closeness; they should understand that in Qlik we always show hard data, a little humanity doesn't hurt ;). Using reports or subs is useful too.
I hope it helps you... or at least it brought a smile to your face. Greetings from Buenos Aires.
Miguel.
Hi
What about this option
In your data load editor add REST connection
URL: https://tenant.qlikcloud.com/api/v1/users
Query headers:
Name: Authorization
Value: Bearer {your API key}
Check allow "WITH CONNECTION"
and your code will be
Hi @MigueldelCampo , you can try something like below in the Title Expression. Please change the text accordingly.
='Hello ' & Subfield(Subfield(OSUser( ),';',2),'=',2) & ' Welcome to Qlik Sense'
Using the highlighted, we can get the username.
Feel free to revert in case anything.
Hi
What about this option
In your data load editor add REST connection
URL: https://tenant.qlikcloud.com/api/v1/users
Query headers:
Name: Authorization
Value: Bearer {your API key}
Check allow "WITH CONNECTION"
and your code will be