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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
hilmandenis
Contributor
Contributor

StringIndexOutOfBoundsException error on tMap

Hi everyone,

I have a tMap and use a substring formula on 1 of the lookup column. The formula is like this 

row4.Merchandising_Code.substring(1,3) 

When I run, I got an error says StringIndexOutOfBoundException: String Index Out Of Range: 3. When I look into my column values, there's some of the value that has 3 characters and there's also a blank value. After searching in this forum, I changed my query into this one

row4.Merchandising_Code.substring(1,Math.min(3, row4.Merchandising_Code.length()))

But I still got an error and now its String Index Out Of Range: -1. I think it because of the blank value. What should I change in the formula to catch blank values?

1 Solution

Accepted Solutions
manodwhb
Champion II
Champion II

@Hilman Utomo​ , can you try to use the below on.so you will not get IndexOutOfBoundsException.

 

row4.Merchandising_Code.length()>3?row4.Merchandising_Code.substring(1,3) :row4.Merchandising_Code

 

 

Thanks,

Manohar

 

View solution in original post

2 Replies
manodwhb
Champion II
Champion II

@Hilman Utomo​ , can you try to use the below on.so you will not get IndexOutOfBoundsException.

 

row4.Merchandising_Code.length()>3?row4.Merchandising_Code.substring(1,3) :row4.Merchandising_Code

 

 

Thanks,

Manohar

 

hilmandenis
Contributor
Contributor
Author

Thanks a lot, Sir