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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Can i use dynamic name to call name context ?

Hello,

 

I have different name context like :

user12 = johnny

user20 = bob

user54 = billy

 

I my job, i have my id user. 

 

Can i use a dynamic name context like :

context."user"+id

or

String my_user = "user"+id;

context.my_user

 

I try more syntaxes but it's not ok

 

Thanks for your help,

Arnaud

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

I find a solution with a method context : getProperty()

 

String my_user = context.getProperty("user" + current_id);

 

It works !

 

If my current_id doesn't match with an existing context name as context.getProperty("user" + 25465)

> return null

 

Thanks everyone !!

View solution in original post

5 Replies
aashish_21nov
Creator
Creator

no for context variable you can't do so.

I try to help you if you explain your problem more clearly

aashish_21nov
Creator
Creator

or you can do with the below strategy(in tJava component):

int id=25;

context.my_user = context.user+id; //where id is a variable

 

Anonymous
Not applicable
Author

Here is my context.

 

0683p000009LyJw.png

 

To get my context :

context.user12 > I have my response : johnny

 

Now, i want to get my context dynamically. I try different syntaxes but it's not ok

current_id = 12

context."user"+current_id > cannot be resolved

context.user+current_id > cannot be resolved

 

Do you have any idea ?

TRF
Champion II
Champion II

You cannot construct context variable names as they must exist at compile time.

On the other hand, you can do it with global variables but depending of why you try to do, maybe it's not a solution for you.

Anonymous
Not applicable
Author

I find a solution with a method context : getProperty()

 

String my_user = context.getProperty("user" + current_id);

 

It works !

 

If my current_id doesn't match with an existing context name as context.getProperty("user" + 25465)

> return null

 

Thanks everyone !!