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

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Replace String tMap with conditions

Hello,
I would like a table in my tMap OTC powering an Libelle column via a condition like: (row1.Chef_de_Site==null)row1.Chef_de_Projet:row1.Chef_de_Site.
But each time it references null me and suddenly my Libelle column is empty.
Thank you in advance.
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Your test for an empty String is wrong. The "==" operator checks for the same object, not the same value. You need to use something like below to check for both null and an empty String....
row1.Chef_de_Site!=null && row1.Chef_de_Site.trim().compareToIgnoreCase("")!=0  ? row1.Chef_de_Site : row1.Chef_de_Projet
The above test ensures that the column neither holds a null or an empty String. If that is true, then it returns the column. Otherwise it will return the other column. The null is checked first and that is important since if the column is null, none of the methods on the object will work. 
If that produces a blank field try below....
row1.Chef_de_Site!=null && row1.Chef_de_Site.trim().compareToIgnoreCase("")!=0  ? row1.Chef_de_Site : "NOT BLANK"
If that produces a blank, you have another problem somewhere else. If it does not and outputs "NOT BLANK" it means your Chef_de_Projet is blank.

View solution in original post

4 Replies
Anonymous
Not applicable
Author

There are several things that could be happening here. Here are the things I would check....
1) The command looks wrong, but that could just be how you transferred it from your job to here. It should be...
row1.Chef_de_Site==null ? row1.Chef_de_Projet : row1.Chef_de_Site
2) Are you sure that row1.Chef_de_Site is null and not an empty String ("")?
3) Are you sure that row1.Chef_de_Projet has a value when row1.Chef_de_Site is null?
Anonymous
Not applicable
Author

I also try to do: row1.Chef_de_Site == ""? row1.Chef project: row1.Chef_de_Site but when I test the condition tMap me it shows null.
Yes if Chef_de_Site is empty Chef_de_Projet is necessarily filled, the 2 columns can not be empty and 2 columns can be filled 2 but in this case I want Chef_de_Site.
Anonymous
Not applicable
Author

Your test for an empty String is wrong. The "==" operator checks for the same object, not the same value. You need to use something like below to check for both null and an empty String....
row1.Chef_de_Site!=null && row1.Chef_de_Site.trim().compareToIgnoreCase("")!=0  ? row1.Chef_de_Site : row1.Chef_de_Projet
The above test ensures that the column neither holds a null or an empty String. If that is true, then it returns the column. Otherwise it will return the other column. The null is checked first and that is important since if the column is null, none of the methods on the object will work. 
If that produces a blank field try below....
row1.Chef_de_Site!=null && row1.Chef_de_Site.trim().compareToIgnoreCase("")!=0  ? row1.Chef_de_Site : "NOT BLANK"
If that produces a blank, you have another problem somewhere else. If it does not and outputs "NOT BLANK" it means your Chef_de_Projet is blank.
Anonymous
Not applicable
Author

OK ... The first test of my condition in the tMap put me null when in fact it works without worries