Macro editor for macro functions defined by the user
A separate macro editor is available for definition and test execution of user-defined macro functions in JavaScript syntax. This macro editor is similar in structure to the macro editor for internal macro functions.
The macro editor for user-defined macro functions is split into the work spaces Code, Test, and Result.
Use the Code tab to define custom macro functions. In the dedicated input area, you can edit the JavaScript program code of the macro function. Display of line numbers, syntax highlighting, and code folding are supported.
You will only need to specify the program code within the function body. At runtime, the program will generate the function header, including the curly brackets around the code block (see property CustomJsMacro.Macro[].Code).
The Test tab is for executing the JavaScript function as a test.
If the JavaScript function contains call parameters (defined in CustomJsMacro.Macro[].Params), you can specify test values for these parameters. When specifying multiple test values, separate with commas. Use the syntax of a literal (constant value) or array of the internal macro interpreter. The program itself will execute conversion to the equivalent JavaScript data type.
Alternatively, you can specify variables as a parameter value in the form @variable name. If the variable is a field variable, specify the current value of this field variable in the table for the field contents of the test document. Also store the test values of all other fields that are accessed directly in the program code of the macro there. If no values are stored, the fields will implicitly retain the default values. Access all fields and other properties of the test document in the code via the doc object. This object is globally available and ensures that the test document is transferred to the JavaScript environment (see User-defined macro functions).
For write access to document fields, specify these fields in advance. Within the JavaScript environment, fields cannot be added dynamically to the test document (except for new table rows). You can define header data fields in the test document. Note, however, that this kind of a definition will not suffice for tabular fields. For this reason, we advise selecting a scenario configuration and a field catalog. The test document will then use the fields and the initial values of these fields.
The purpose of the Result tab is to display the result that the test carried out.
Execution will have one of two results: 1) a return value; or 2) in the case of a document macro, altered field contents for the test document. In addition, if generated from your own program code using the global log() method, log outputs will be displayed. You can use this log output when you are creating your macros for debug information for error analysis.