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

Announcements
Only at Qlik Connect! Guest keynote Jesse Cole shares his secrets for daring to be different. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Sudhee_Maximus
Creator
Creator

How to get global variable value (which is already defined) using value of a variable in java dynamically

Hi there ,

I have code something like below, I am trying to retrieve global variable values (saved in tsetglobalvar) based on the lookup values .

I have written javacode to separate each string value and trying to retrieve values from global variable based on the string value separated using java code .

//Code generated according to input schema and output schema

String str ;

String x=null;

/* below values coming from an API output */

output_row.ROW_ID = input_row.ROW_NUM;

output_row.JOB_ID = input_row.JOB_ID;

output_row.END_POINT = input_row.END_POINT;

output_row.STATUSCODE = input_row.STATUSCODE;

output_row.STRING = input_row.STRING;

output_row.BODY = input_row.BODY;

str=output_row.BODY;

/*java code to split string values */

 String[] arrOfStr = str.split("\",\"");

 for (String a : arrOfStr)

 { 

/* trying to assign value to x by retrieving value of a (extracted value of string ) if available using globalMap.get(a)

(This is erroring out )

*/

      if(x==null)

      x=((String)globalMap.get(a));

      else

     x=x+","+

((String)globalMap.get(a))

  ;

      }

      System.out.println(x);

       

      output_row.Warnings=x;

can you guys please help me with the code to get the global variable value for "a" ?

Thanks & Regards,

Sudheendra

Labels (2)
4 Replies
Anonymous
Not applicable

Hi

Can you share a screenshot of the job? Please show us where do you put the value to global variable.

 

Regards

Shong

Sudhee_Maximus
Creator
Creator
Author

Hi Shong,

 

Please find the screenshot attached ....please let me know if you need more details ...

the java code highligheted is where I have written this code

 

0693p00000AHjd9AAD.png

Sudhee_Maximus
Creator
Creator
Author

Thanks a lot for looking into this

 

Anonymous
Not applicable

From your screenshot, I think you always get the last value from the global variable, if you want to iterate each value, you need to use tFlowToIterate component, for example.

tHashInput--mainI(row1)--tFlowToIterate--iterate--tJava--oncomponentok--tMysqlInput--main--tJavaRow

 

on tJavaRow, you can retrieve value of global variable like:

 

String str ;

 

String x=null;

output_row.BODY = input_row.BODY;

str=output_row.BODY;

 

String[] arrOfStr = str.split("\",\"");

 for (String a : arrOfStr)

 { 

 

 

      if(x==null)

      x=((String)globalMap.get(row1.columnName));

      else

     x=x+","+

((String)globalMap.get(row1.columnName))

  ;

      }

      System.out.println(x);