Six Stars

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

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: Can i use dynamic name to call name context ?

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 !!

5 REPLIES
Five Stars

Re: Can i use dynamic name to call name context ?

no for context variable you can't do so.

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

Regards
Aashish
Five Stars

Re: Can i use dynamic name to call name context ?

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

 

Regards
Aashish
Six Stars

Re: Can i use dynamic name to call name context ?

Here is my context.

 

context_user.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 ?

Forteen Stars TRF
Forteen Stars

Re: Can i use dynamic name to call name context ?

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.


TRF
Six Stars

Re: Can i use dynamic name to call name context ?

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 !!