Token in Variable field

I want to create a variable based on the name of the running macro.
The Variable field in the set variable to text action is allowing it:

However I can't use this variable further down in other Variables fields:

The red value in the field is ignored by KM.
It seems that the Variable field validation rules are different in these actions.
Is this Normal ?
Is there a way to solve this ?

You can get at the data stored in a Variable that has part of its name formed from a Token or another Variable (i.e. part of its name in %s) by using a Filter Action with "Value of Named Variable" as the filter.

Notice how in the Filter Action the dynamically named Variable is filtered as "Text".

EXAMPLE__Dynamic named Variable Value.kmmacros (4.8 KB)

Click to Show Image of Macro

2 Likes

I admit it does seem inconsistent that KM sometimes allows you to use tokens where variable are expected. Both of the labels at the right side of the following input boxes say "V", but both boxes don't work the same way, because one allows tokens and the other doesn't. It does seem like a labelling issue in the KM Editor at the minimum.

Perhaps the "V" label should be "V+" when the box supports tokens, and just a "V" when it doesn't.

3 Likes

Why are you doing this -- is it so that you can create a Global variable based on the name of the executing macro? If so you are probably better off creating a Dictionary and posting a key-value pair to that, using the macro's name as the key.

@Zabobon's method is great, but you'll need to include the "Filter" action before every conditional that uses your dynamic variable, in case it has been changed since the last Filter:

EXAMPLE__Dynamic failure.kmmacros (5.2 KB)

Image

...which is odd, because I'd always assumed we were Filtering to generate a Token while the above implies it then evaluates that Token to its value.

2 Likes

The Set Variable action is the only action that allows variable names to have tokens.

In other places that accept variable, you have to specify the variable explicitly.

If you need to read a variable dynamically, you can use something like the Filter action with Value of Named Variable.

4 Likes

Ah yes. That is more direct than "Process tokens" so, I have edited my post above to show that.

I also agree with @Nige_S that using a Dictionary is a better approach to this as Dictionaries can include Variables/Tokens in their names and in their keys with no need to use a Filter Action to get at the data.

EXAMPLE__Dictionary with Token as Key.kmmacros (4.3 KB)

1 Like