Saving Variable Name inside another variable

Is it possible to save a Variable Name inside another variable?
I have many Global Properties, all with a similar name like:

Item A Cost
Item A Amount
Item B Cost
Item B Amount
Item C Cost
Item C Amount

and so on…
If I have a Property Item containing “Item A” or “Item B” and another property Type containing “Amount” or “Cost” may I get the value of one of the previous Global Property using these two local properties (maybe in a text label) like
$Item$ + " " + $Type$ or
$$Item$ $Type$$ or something…

In other words if I have
Item=“Item A”
Type=“Amount”
Item A Amount=5

I would like to use a text label pointing $Item A Amount$ not directly using the name of such Global Variable but using the two local variables to have a text with the value 5 saved in the Global Var.

Thanks.

Yes, you can do this, with the caveat that if you want to use spaces in the property names, I believe you must use BeanShell syntax to access them. Using your suggested names and values, you could use {GetProperty(Item + " " + Type)} to get 5, the value of the property Item A Amount.

2 Likes

It works, Thanks a lot.

If I want to show the {GetProperty(Item + " " + Type)} in a text is there a way to write it directly inside the “label text” or should I have to use first a Calculated Property (named for es. textToDisplay) and then have a Text Label referring to $textToDisplay$?
I mean like this:

textToDisplay (Calculated Property): {GetProperty(Item + " " + Type)}
text label: $textToDisplay$

In addition to the previous question…
May I use the value of the {GetProperty(Item + " " + Type)} property directly in another one?
Let’s say {GetProperty(Item + " " + Type)}=10
Is it possible to use a calculated property which calculates directly the double of such property like this?
CalProp: {GetProperty(Item + " " + Type)} *2

It does not seem to work.
I have to use two steps:
CalcPropA:{GetProperty(Item + " " + Type)}
CalcPropB: CalcPropA*2

Is this correct?

If you’re using BeanShell syntax, the entire statement needs to be in BeanShell; e.g., to use GetProperty(Item + " " + Type) in a text label to say “Amount = 5”, You would need the Text Label to be {"Amount = " + GetProperty(Item + " " + Type)}; you can’t have anything outside the curly braces {}. I think that works in a text label, but if I’m misremembering, the alternative would be to set up a Calculated Property with the value GetProperty(Item + " " + Type), then set your Text Label to be Amount = $CalcProp$ (assuming that’s what you named the Calculated Property).

For your 2nd question, again, the entire thing needs to be inside the curly braces, like so: {GetProperty(Item + " " + Type) * 2}.

Most fields that accept BeanShell syntax have a calculator icon at the right end of the field; this will bring up the BeanShell editor window, which has a drop down menu to add many useful BeanShell functions, and will show a green checkmark if your syntax is good (or a red X if not).

Edit: Calculated Properties (CP) must use BeanShell syntax, and the curly braces are added automatically for CPs only; don’t type the curly braces yourself if you’re setting up a CP.