How to use Global Variables to populate Macro Variables in a HATS Transformation Macro
If you want to populate a macro variable with a global variable value, there is an easy way to do so.
The first step is to make sure that there is a global variable to prompt from.
Create a Global Variable
- In your screen customization, go to the Actions tab.
- Choose Add and select Set Global Variable.
- Name the global variable and give it an initial value so that we can use it in the macro later.
- Click Finish and make sure that the actions are in the proper order (the Set Global Variable should be before the Play Macro).
Now we need to make sure that your macro is set up to work with macro variables, and that the macro has a macro variable available to work with.
Create a Macro Variable
- Open up the macro with the Visual Macro Editor.
- Right click on the screen and choose properties.
- In the properties panel choose Variables and Types.
- Make sure the choice for Enable support for variables and arithmetic expressions is enabled.
- If you have a macro variable, make sure it is available, otherwise create a macro variable on this page.
- To create a macro variable, click Add and give the variable a name (you do NOT need $ symbols around the name for this wizard) and a value (string values require single quotes) and press Finish.
This macro variable will show in the source view as
<create name="$testMV1$" type="string" value="'hello world!'"/>
Now that we have a valid macro variable, we can use it in the prompt action.
Create a Prompt Action
- In the macro, create a new prompt action using the Visual Macro Editor. In the macro main view, right click on the screen that you wish to modify and choose properties.
- Choose Actions. In the actions table, choose Add. When given the choice of what action to add, choose Prompt.
- In the Prompt panel, name the prompt, select save value to variable and choose the correct macro variable. Make sure to enable Do not insert value into field unless it was specifically your intention to do otherwise. For the handler, choose Set prompt to global variable and choose the correct global variable. Press Finish and make sure that the new prompt action is in the correct place in the list.
In the source view you can see that the following action was added to the screen.
<prompt assigntovar="$testMV1$" clearfield="false" col="0" default="" description="" encrypted="false" len="80" movecursor="false" name="'gv_to_mv'" required="false" row="0" title="" varupdateonly="true" xlatehostkeys="false"/>
Note that the assigntovar parameter has the macro variable name with the $ symbol surrounding the macro variable name. Also notice that the varupdateonly parameter in the prompt action was set to true, so that we will not accidentally change the host screen.
We are finished, and now can get our global variable value to our macro variable!
Next time I will cover how to copy data in the other direction, from a macro variable to a global variable.