Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
MigueldelCampo
Contributor III
Contributor III

How to display the logged-in user’s name in Qlik using OSUser() and the USERS table

buenosdias.jpg

 

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.

 

 

Labels (7)
1 Solution

Accepted Solutions
BPiotrowski
Partner - Creator
Partner - Creator

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 

 

LIB CONNECT TO 'Space:Connctionname';
 
RestConnectorMasterTable:
SQL SELECT 
"__KEY_root",
(SELECT 
"subject",
"name",
"email",
"__FK_data",
"__KEY_data"
FROM "data" PK "__KEY_data" FK "__FK_data")
FROM JSON (wrap on) "root" PK "__KEY_root";
 
[data]:
LOAD [subject],
[name],
[email]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_data]);
 
 
DROP TABLE RestConnectorMasterTable;
 
 
Now data table contains:
subject: auth0|xxxxxxxxxxx
name: First name Last Name
 
Remember to hide these fields from users:

TAG FIELD [subject] WITH '$hidden';
TAG FIELD [name] WITH '$hidden';
TAG FIELD [email] WITH '$hidden';

Then in KPI expression just use:
'Hello ' & Only({<subject= {"$(=SubField(OSUser(),'=',-1))"}>} name) & ' Welcome to Qlik Sense'
 
Think its clear and dynamic option to get name of user in cloud 😉
 

View solution in original post

2 Replies
Kaushik2020
Creator III
Creator III

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. 

BPiotrowski
Partner - Creator
Partner - Creator

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 

 

LIB CONNECT TO 'Space:Connctionname';
 
RestConnectorMasterTable:
SQL SELECT 
"__KEY_root",
(SELECT 
"subject",
"name",
"email",
"__FK_data",
"__KEY_data"
FROM "data" PK "__KEY_data" FK "__FK_data")
FROM JSON (wrap on) "root" PK "__KEY_root";
 
[data]:
LOAD [subject],
[name],
[email]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_data]);
 
 
DROP TABLE RestConnectorMasterTable;
 
 
Now data table contains:
subject: auth0|xxxxxxxxxxx
name: First name Last Name
 
Remember to hide these fields from users:

TAG FIELD [subject] WITH '$hidden';
TAG FIELD [name] WITH '$hidden';
TAG FIELD [email] WITH '$hidden';

Then in KPI expression just use:
'Hello ' & Only({<subject= {"$(=SubField(OSUser(),'=',-1))"}>} name) & ' Welcome to Qlik Sense'
 
Think its clear and dynamic option to get name of user in cloud 😉