Macro Variables

Previous  Next |  Direct link to this topic


Online E-Learning is also available for this feature. Click here to watch it


It is possible to have a macro that before execution will ask for input before execution. This feature is called Macro Variables


You can ask for up to 20 variables using the [%0], [%1] ... [%19] syntax




What you do is to simple put the variable keyword as a placeholder for where you want your value to appear. You can use the same variable multiple times and in any order.


You then press the Variables button to define the individual variable's format







The variable you are defining the source for


The Source. It can a custom value or a list of common values like Business partners etc.

If can find the list of value you wish you also have the option to define a SQL sentence that should retrieve the values as a combo box.


The caption of the variable (The text shown when prompting the user for the value)

Source SQL

If you in the Source select SQL as source, you define the SQL here (else it is not used). The SQL sentence should be a SELECT statement with two selected columns. first value will be seen as the value of the selection and second will be seen as the description.


Sample: SELECT CardCode, CardName FROM OCRD

would result in a list of all Business Partners. CardCode will be the value for the customer select and CardName will be the description that help them choose the value.


The title of the window shown when prompting the user for the values



When you use the Macro it will instead of execution prompt you for the configured input




and once the OK Button is pressed the Macro will execute.


Tip: All Macros use the same window to ask for their input. You might however want to use the B1 Validation System to validate the input before execution, but if you only did the validation on the FormType you would affect multiple configurations. For that reason a special Keyword $[$UFCODE.0.0] can be used to know what UF-Code create the input screen. Here is a small sample where the above input screen is validated of having a value in Item 1 (Item BOY_19):



NB: You can't create above B1 Validation System via normal Right-click functionality as the Macro Vars form is Modal. You will need to open the B1 Validation Config manually and enter all the values


Important information about limitations and format:


All Macro variables are collected upfront and are not a blocking operation (technical limitation from the SDK) so you can as an example use Macro Variable to ask for missing data prior to pressing an Add button (the result would be that the macro prompt would appear but SAP Business One would have already proceeded with the Adding on the business object).

Macro-prompt is a modal form so while on screen you can't go to any of the other screens in SAP Business One

Values that replace the Macro Variables keywords are formatted for usage in the SAP Gui. This means dates are in format yyyy-MM-dd and decimal values are use . (dot) as comma separator and no thousands separator. This mean that if you wish to display the input value to the user you need to format them using SQL:

A Macro vars prompt is not possible to confirm via Enter as normal (Technical limitation from SAP). You always need to use the Mouse to press the OK button.

The special keywords $[CURRENT_ITEM] and $[CURRENT_COLUMN] can't be used in the same macro as a Macro Variable

Dot Net Snippets can't reference the underlying Item-event if used in a Macro that uses Macro variables.