Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
michael_luettge
Contributor
Contributor

If statement with variable won't work

Hello specialists,

I need help for a coding problem that I'm not understanding.

In my script I query the actual user with:

Let vBenutzer = QVUser();

Then I like to decide with a "IF" statement which text a second variable should have:

If(vBenutzer = 'XXX', 'EN', 'DE') as Language;

I have tried many versions of the "IF" statements but nothing works.

Please can every specialist give me support?

Thanks in advance!

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Do you have section access in the application? If not, you might have to use OSUser() instead of qvuser(). And the code you use need some correction as well, like:

Let vBenutzer = QVUser();  // Or, OSUser()

Let Sprache =If( vBenutzer = 'XXX', 'EN', 'DE') ;     

If Sprache = 'DE' then

     SET A1 = 'Title DE 1';

     SET A2 = 'Title DE 2';

end if;

If Sprache = 'EN' then

     SET A1 = 'Title EN 1';

     SET A2 = 'Title EN 2';

end if;

View solution in original post

7 Replies
vishsaggi
Champion III
Champion III

Try this?

If( $(vBenutzer) = 'XXX', 'EN', 'DE')

michael_luettge
Contributor
Contributor
Author

Hello !

Sorry, but won't work. I receive the message "Error in Expression" if I change the statement to this:

If( $(vBenutzer) = 'XXX', 'EN', 'DE') as Language;

The cursor indicates the " , " as the problem and I don't understand why?

Can anyone give an advise?

Thank you in advance.

chinnuchinni
Creator III
Creator III

Can you please post your script once.

michael_luettge
Contributor
Contributor
Author

Hello,

it's a short script until now. I like to check which user has opened the application. Then I like to decide in which

language should Qlikview shows the titles of the tables. But the script shows me an error in the first "if" statement

and indicates that the " , " should be the problem.

Let vBenutzer = QVUser();

If( $(vBenutzer) = 'XXX', 'EN', 'DE') as Sprache;

If Sprache = 'DE' then

     SET A1 = 'Title DE 1';

     SET A2 = 'Title DE 2';

end if;

If Sprache = 'EN' then

     SET A1 = 'Title EN 1';

     SET A2 = 'Title EN 2';

end if;

Thank you for every advise.

tresesco
MVP
MVP

Do you have section access in the application? If not, you might have to use OSUser() instead of qvuser(). And the code you use need some correction as well, like:

Let vBenutzer = QVUser();  // Or, OSUser()

Let Sprache =If( vBenutzer = 'XXX', 'EN', 'DE') ;     

If Sprache = 'DE' then

     SET A1 = 'Title DE 1';

     SET A2 = 'Title DE 2';

end if;

If Sprache = 'EN' then

     SET A1 = 'Title EN 1';

     SET A2 = 'Title EN 2';

end if;

michael_luettge
Contributor
Contributor
Author

Thank you a lot, that was the solution !

marcus_sommer

In your case the variable contains a string and therefore you need single-quotes around it by calling them, like:

If('$(vBenutzer)' = 'XXX', 'EN', 'DE')

Beside this I assume that you rather need osuser() instead of qvuser() which is only available if you used section access with USERID.

Further I suggest to consider to use the function directly instead of creating an additionally variable which adds here no value, maybe in this way:

if(match(osuser(), 'User1', 'User2', ...), 'EN', 'DE')

- Marcus