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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
rp2018
Creator
Creator

How to write if then else in tjavarow?

I'm trying to write a case statement in tjavarow using if then else.   This is what I've written and it's not working.  

 

output_row.Value = if (input_row.Value = "MP\/MM") {   
output_row.Value = "MP / MM";
} else if (input_row.Value = "T \u200 MM") {
output_row.Value = "T - M";
} else if (input_row.Value = "T \u200 ND") {
output_row.Value = "T - ND";
} else if (input_row.Value = "T LF") {
output_row.Value = "LF";
} else {
output_row.Value = input_row.Value; 
}

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

I suspect that is caused by this "MP\/MM". Change it to "MP\\/MM" and that will work. "\" is known as an escape character in Java. Certain characters have alternative meanings/uses in Strings. For example, a " character is used to enclose a String, if used inside the String without an escape character, it breaks the String. The "\" character is the escape character, so to use it literally you need to escape it.

View solution in original post

4 Replies
TRF
Champion II
Champion II

You must follow Java rules.
1st, remove "output_row.Value =" from the beginning
2nd, don't use == for strings comparison, use String.equals method. For example, you should write
if ("MP\/MM".equals(input_row.Value))
rp2018
Creator
Creator
Author

After making the change per below suggestion.  Now, I'm getting following error message.

Detail Message: Invalid escape sequence (valid ones are  \b  \t  \n  \f  \r  \"  \'  \\ )

Anonymous
Not applicable

I suspect that is caused by this "MP\/MM". Change it to "MP\\/MM" and that will work. "\" is known as an escape character in Java. Certain characters have alternative meanings/uses in Strings. For example, a " character is used to enclose a String, if used inside the String without an escape character, it breaks the String. The "\" character is the escape character, so to use it literally you need to escape it.

rp2018
Creator
Creator
Author

Resolved it by adding \ front of the escape character