Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
alenb
Partner - Contributor III
Partner - Contributor III

Show condition based on OSUser

Looking at the following two tables, the intent was that user FRED is part of Team1, which has accesses to Brands a and b.

 

Brands:
LOAD * Inline [
Team, Brand
1, a
1, b
2, b
2, c
];

 

Users:
User, Team1, Team2
FRED, admin, user
WILMER, user

 

Then I wanted to create a container with filter panes, wherein each filter pane shows only to the user that belongs to approprirate team. 

 

1. This worked. I hardcoded the FRED user and the following show condition worked correctly.

Len(only({<UserID={'FRED'}>}[Team1])) > 0

 

2. Then I tried to use the actual logged-in user instead of FRED, and after many modifications of the following code it still does not work. 

Expression for getting username: Upper(SubField(OSUser(), '=', -1)). This alone works as expected. 

2.1. No Error but doesn't work 

Len(only({<UserID={"Upper(SubField(OSUser(), '=', -1))"}>}[Team1])) > 0

 

2.2. The following variations all gave me "garbage in expression" error

Len(only({<UserID={Upper(SubField(OSUser(), '=', -1))}>}[Team1])) > 0

Len(only({<UserID=Upper(SubField(OSUser(), '=', -1))>}[Team1])) > 0

Len(only({<UserID=$(Upper(SubField(OSUser(), '=', -1)))>}[Team1])) > 0

 

3. Using just the OSUser() inside the condition also worked in this way. 

Len(Upper(SubField(OSUser(), '=', -1))) > 0

 

Bonus question: in chart expressions, can I declare variables for simplifying the code. For example:

SET vUser: Upper(SubField(OSUser(), '=', -1))

Len(only({<UserID={$(vUser)}>}[Team1])) > 0

 

 

 

 

1 Solution

Accepted Solutions
GaryGiles
Specialist
Specialist

I think you need to enclose your Upper expression in a $ expansion, like this:

Len(only({<UserID={"$(=Upper(SubField(OSUser(), '=', -1)))"}>}[Team1])) > 0

View solution in original post

2 Replies
GaryGiles
Specialist
Specialist

I think you need to enclose your Upper expression in a $ expansion, like this:

Len(only({<UserID={"$(=Upper(SubField(OSUser(), '=', -1)))"}>}[Team1])) > 0

alenb
Partner - Contributor III
Partner - Contributor III
Author

The trick that I missed was to use = inside the $(). Works like a charm now, thanks!