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: 
Vinlogs
Creator
Creator

how to use context variable in a tMap output filter section

Hi All, I am Currently reading data from a source file and I want to filter specific records from a column row1.abc and I am using the below condition

" row1.abc == 1 || row1.abc ==2|| row1.abc ==3 " in tMap output side filter section.

Requirement- I want to pass the values 1,2,3 to the above expression using a context variable in tMap output filter. Please help me how to achieve this. Thanks in advance..!😊

Labels (3)
1 Solution

Accepted Solutions
8 Replies
gjeremy1617088143

Hi, so you want all the values in one variable or one variable for each value ?

Send me love and kudos

Vinlogs
Creator
Creator
Author

Hi, Thanks for responding. I want all values in one context variable if possible.

gjeremy1617088143

use a context variable

here the name i use is list1 and value is "1,2,3" as String

 

then in a tJava a the begining of the job

in advanced settings of the tJava:

 

import java.util.List;

import java.util.ArrayList;

import java.util.Arrays;

 

in the basic settings of the tJava :

 

List<String> str = (Arrays.asList(context.list1.split(",")));

List<Integer> intList = new ArrayList<>();

str.forEach(a-> intList.add(Integer.parseInt(a)));

globalMap.put("intList", intList);

 

 

and in the tmap filter output expression :

 

((List<Integer>)globalMap.get("intList")).contains(row1.abc)

 

send me love and kudos

Vinlogs
Creator
Creator
Author

I have defined the code in tJava component as you mentioned and created a context variable with string data type and inserted value 22,38,39 in contexts section. But I am getting below error-0695b00000OB2w5AAD.jpg0695b00000OB2x8AAD.jpgplease advise.

gjeremy1617088143

could you go to the code view and share screen where the error is. you can find it where there is red square. cause i test this particular piece of code and it's working

Vinlogs
Creator
Creator
Author

Thanks for sharing your screenshots, I am not able to see any errors in code view. But after I changed my string data type context variable value with enclosed double quotes "22,38,39" I am getting below error upon job run - {"logTimestamp":1644835697403,"severity":"FATAL","logType":null,"logMessage":"tJava_3 For input string: \"\"\njava.lang.NumberFormatException: For input string: \"\"\n\tat java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)\n\tat java.lang.Integer.parseInt(Integer.java:592)\n\tat

Vinlogs
Creator
Creator
Author

Thanks, @guenneguez jeremy​ !! The solution you provided did work. Appreciate your detailed solution with screenshots. Love and Kudos!