Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How can I load expression conditionally?

In our application, we have 6 expressions to aggregate data.

However, depending on user's security setting, most users should ONLY see 3 expressions loaded in list box. So I need a way to load Expression listbox dynamiclly.

I had following codes in my loading script, but it does not work:

secTmp:
select securityToken from $(DBOWNER).sysSecurity where logonid = QVUser()
let secToken = FieldValue(securityToken,1);

Exp:
load * inline [Exp
Sales
SaleQty
% of Total Sales
] ;

if ($(secToken)= 'Y') then
concatenate( Exp)
load * inline [Exp
COGS
Margin
Margin %
] ;
end if

Qlikview first complained QVUser is not a valid function, and then complained my if block has syntax error.

Anyone help me ??? Thanks!



1 Solution

Accepted Solutions
stephencredmond
Luminary Alumni
Luminary Alumni

Hi,

This solution won't work because, as you have identified, the QVUser() function is not relevant at load time. Even if it was, it would return the user who was performing the reload, not one of your end users.

What you should probably look at is linking the users to the data like this:



Section Access;
LOAD * INLINE [
ACCESS, USERID, TOKEN
ADMIN, ADMIN, *
USER, USER1, Y
USER, USER2, N
];
Section Application;

ListBox:
LOAD * INLINE [
TOKEN, ListboxValue
Y, A
N, A
Y, B
N, B
Y, C
];<div>
Note that the "TOKEN" field must be in caps and the values in it must be caps too.
Now, when User1 logs in they will see A, B, C. When user2 logs in they will see just A,B.
Also note that this field doesn't have to be related to the rest of your dataset. If it is though, User2 will also not see any data that is associated with the "C" value.
Regards,
Stephen


View solution in original post

4 Replies
Miguel_Angel_Baeyens

Hello Paul,

I see some syntax errors, that may be typos when writing this post, but it's worth looking at it in your original code:

select securityToken from $(DBOWNER).sysSecurity where logonid = 'QVUser()'; // quoted since it's a literal and semicolon to end the line let secToken = FieldValue('securityToken',1); // fieldnames in fieldvalue are always quoted


Now it should work.

Not applicable
Author

I wish I had addressed my issue more clear in original post.

I have users list stored in a security table, and the user list is loaded in Section access.

Say, 2 users,

User Token
A Y
B N

Then I have a listbox called 'Expression' , which is using inline load in Section Application.

My requirement is: when a user's Token is 'Y', I want the listbox be loaded values A and B and C;
when a user's Token is 'N', I want the listbox be loaded values A and B only (without C).

Kind of dynamic loading of a listbox, depending on user's setting.

I am not sure if I can use function QVUser() in loading script since QVUser() is used to access who is opening my document on the server.

I checked Qlikview's data reduction and still don't get the idea.

Any idea? Thanks!

stephencredmond
Luminary Alumni
Luminary Alumni

Hi,

This solution won't work because, as you have identified, the QVUser() function is not relevant at load time. Even if it was, it would return the user who was performing the reload, not one of your end users.

What you should probably look at is linking the users to the data like this:



Section Access;
LOAD * INLINE [
ACCESS, USERID, TOKEN
ADMIN, ADMIN, *
USER, USER1, Y
USER, USER2, N
];
Section Application;

ListBox:
LOAD * INLINE [
TOKEN, ListboxValue
Y, A
N, A
Y, B
N, B
Y, C
];<div>
Note that the "TOKEN" field must be in caps and the values in it must be caps too.
Now, when User1 logs in they will see A, B, C. When user2 logs in they will see just A,B.
Also note that this field doesn't have to be related to the rest of your dataset. If it is though, User2 will also not see any data that is associated with the "C" value.
Regards,
Stephen


Not applicable
Author

Steve, thanks and your solution works!

The only addition to your solution is I need to load Y and N to the token.

LOAD * INLINE [TOKEN
Y,
N];