Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Amit4
Contributor III
Contributor III

Store Max ID using tJava and use it in tMap

Hi @Shong_888 ,

I am storing max(ID) from query and in tJava.

Which I am trying to use and max(ID)+1 in 

Amit4_0-1718016282551.png

Inside tjava:

Amit4_1-1718017688055.png

 

I am struggling to use it in tMap. How can I do that?

Amit4_3-1718017935812.png

 

Please help!

 

Thanks in advance!

 

Amit

 

 

Labels (6)
2 Solutions

Accepted Solutions
Shicong_Hong
Support
Support

Define the context variable with Bigdecimal type, try this code on tJavaRow:

context.MaxID=input_row.MAX_ID.add(new java.math.BigDecimal(1));

View solution in original post

Amit4
Contributor III
Contributor III
Author

I used the Numeric sequence is variable an and used in map.

Var.varIncrementedID = context.MaxID.add(new BigDecimal(Numeric.sequence("s1", 1, 1)))

Amit4_0-1718464532910.png

Now it's working as expected.

Thanks,

Amit

View solution in original post

12 Replies
Amit4
Contributor III
Contributor III
Author

If we can do in any other way to store the max id and use it in tMap. Idea is welcomed.
Thanks!

Amit4
Contributor III
Contributor III
Author

@root 

@JR1 

@Shicong_Hong 

Can you please help in making it successful. 

Thanks in advance.

Shicong_Hong
Support
Support

@Amit4 use tJavaRow instead of tJava, store the max(ID) to a context variable for used later on other components.

tJavaRow code:

context.varName=input_row.MAX_ID;
Amit4
Contributor III
Contributor III
Author

Hi @Shicong_Hong ,

I applied the logic in tJavaRow

Amit4_0-1718180712519.png

 

 

But How can we use that variable in tMap output. Also I want it to be in the incremental form. If ID comes as 100 then it should pass as 101 in the output table.

 

Amit4_1-1718182771813.png

 

Thanks

Shicong_Hong
Support
Support

change the code to 

context.MaxID=input_row.MAX_ID+1;

and use the context variable directly in the expression field of column.

Shicong_Hong_1-1718184738608.png

 

 

Amit4
Contributor III
Contributor III
Author

Thanks but My ID column is of Bigdecimal data type upon adding 1 it is getting failed which is legit.
How can we deal with this data type issue.

ThWabi
Creator II
Creator II

Hello Amit,

I use the tSetGlobalVar component to store a (initial) max id value, and globalMap.get(...) to retrieve it. (I have an Integer data type that is the start value for a Numeric.Sequence(...).)

Best regards,

Thomas

 

 

Shicong_Hong
Support
Support

If ID column is of Bigdecimal data type in output table , use this code in the expression field of column on tMap.

new java.math.BigDecimal(context.MaxID)

 

Amit4
Contributor III
Contributor III
Author

@Shicong_Hong 

Source & Target both table is same and ID column is of BigDecimal data type.

If I use context.MaxID=input_row.MAX_ID+1 in tJavarow, it is throwing error because of integer addition to BigDecimal.

We need handle it before and then use it later in tmap