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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Qlikstu
Partner - Contributor III
Partner - Contributor III

Qlik SaaS - Display user name in an app

HI Everyone 

In Qlik SaaS does anyone have any idea how I can display the name of the user in Qlik SaaS. I'm creating a welcome screen in-app and want their first name (ideally). 

I tried setting a variable LET vUser = OsUser; but this just return the user ID rather than the name. 

Can someone offer some help on this? 

 

Thanks

Stuart

Labels (2)
2 Replies
Aditya_Chitale
Specialist
Specialist

Dalton_Ruer
Support
Support

If OSUser() is returning you a value like

UserDirectory=; UserId=auth0|a08D000001BZigbIAD

 

There is an easy way to convert that into a User Name using the REST API for USERS (which returns all users):

https://qlik.dev/apis/rest/users/

Notice the the value returned from OSUser() is actually the SUBJECT for my user id, and is NOT the ID itself. Knowing that is important, below the image I will show you how to parse out JUST that auth0.... part of what OSUser() returns and then how to fire the API to get the name. 

DaltonUserID.png

You can easily parse out the needed SUBJECT with a command like this:

Let vSubject = SubField(SubField(OSUser(),';',2),'=',2) ;

Since the User API call I mentioned above will return all Users we would really like to give it a "where" clause saying "I want the user(s) where the subject = ...". Just like this: 

https://partner-engineering-saas.us.qlikcloud.com/api/v1/users?subject=auth0|a08D000001BZigbIAD

Yeah I can make that work manually, but how can I make that work inside of my Qlik Sense Cloud application? You really need a 2 step process for that:

Step 1: When you define the REST API connector you need to ensure that you check the Allow "WITH CONNECTION" button near the bottom of the configuration. 

AllowWithConnection.png

After that you can still call the API ... but now you have the option of providing it a different URL, one that is calculated on the fly ... so let's calculate it. Above we set the variable for the Subject, now we can use it: 

Let vProjectInformationURL = 'https://partner-engineering-saas.us.qlikcloud.com/api/v1/users?subject=$(vSubject)';

Essentially recreating the correct URL via code. Now when we call the connection we can say "that URL I gave you to create the connector is old news, please use the URL I just defined for you instead:

ConnectionWith.png

 

The API will be called as you requested so that only your desired SUBJECT is returned, and then it's just a matter of using the PEEK function to pull out the email/name or whatever you want:

[User]:
LOAD
[name_u2] AS [User Name],
[email] as [User Email]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_data]);
 
Let vUserName = Peek('User Name', 0, 'User');
Let vUserEmail = Peek('User Email', 0, 'User');