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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
analyticworld
Contributor
Contributor

Default filer selection based on user login

I am trying to create a default filter selection based on user login and seems like it doesnt work. 
this is what i have done till now: 

LET vUserRaw = OSUser();

LET vUser = Upper(Trim(SubField(SubField('$(vUserRaw)',';',2),'=',2)));

LET vDefaultSelection =
IF(vUser='xxyy','Sweden',
IF(vUser='bbbb','Norway',''));

and used this '$(vDefaultSelection)' in SimpleFieldSelect object under Selections > Select this one as Default. 
However when I reload this app, it works for the UserID who reloaded the app and takes that as the default filter selection and doesnt dynamically change when an other user logs in. 

- its not ideal for all users to reload the app
- this is not to restrict the data, but just to give default filter selections to users based on their area. 
- I tried the actions also on the sheet properties but that doesnt work. 

Anyother way to do this ? so the filterselection changes dymanic



Labels (3)
3 Replies
kauenascimento
Partner - Contributor III
Partner - Contributor III

I had the same idea months ago.

I did like:

Let vCurrentUserEmail = GetUserAttr('userEmail');

Let vCurrentUserID = GetUserAttr('userSubject');

 

rwunderlich
MVP
MVP

You will want to do this dynamically using an expression for the value selection:

=Pick(
WildMatch(OsUser(),
'*=xxyy'
, '*=bbbb'),
'Sweden'
,'Norway)

This works for a small amount of users. For a larger user list, load up a table of userids and Country and use something like this for your selection expression:

=Only({<user={"=Lower(SubField(OsUser(), '=', 2))"}>} Country)

-Rob

Greg_Taffer
Support
Support

To set a default filter based on user login in Qlik Sense, use Section Access to link user IDs to specific data, or create a default bookmark based on OSUser(). For dynamic, non-security filtering, use an action button on sheet initialization to select values using expressions like IF(OSUser()='A','Selection1','Selection2')

 

Key Approaches for Default User Filters

  • Section Access (Recommended for Security): Restrict data at the engine level. By including user login in the load script and linking them to specific dimension values, Qlik automatically filters the data upon opening.
  • Default Bookmarks (UI Level): Define a default bookmark that applies a selection based on the OSUser() function.
  • Sheet Actions/Buttons: Utilize sheet action triggers, such as "Select values in a field" upon opening, where the selection value is derived dynamically from the OSUser() or Email function.
  • "Always One Selected Value": Set this option in the field properties within the filter pane to ensure a single value is always active, which can be combined with expressions for user-specific defaults. 

Common Issues and Tips

  • Dynamic Changes: To ensure the filter changes when another user logs in, ensure the selection formula (e.g., OSUser()) is evaluated dynamically rather than hardcoding a user who reloaded the app.
  • Field Selection Limitation: If the requirement is to lock a user to only their data, ensure the selection is robust (e.g., in a required field).
  • Apply on Sheet Entry: If using sheet actions, ensure they are configured to run when the sheet is visited.