Using HTML Forms in Schedules
Using Forms in Schedules
You can use forms in a schedule, inside HTML files. Values of input elements, such as HTML select elements, are converted to JSON and attached to the Batch Variable (without overriding any other existing batch variables). You can then use JSON macros in ReportMagic to extract the values from your report.
Of course, forms require manual selection so can only be used with Run Now (and not for scheduled runs).
About the HTML file
- The HTML file may contain any standard HTML (including CSS and scripts)
- The HTML file must only contain one <form></form> element
- The HTML file must be valid
- All inputs must be named or they will not be included
- Multi-select inputs (i.e. drop-downs where you want to allow multiple selections) must have the 'multiple' attribute included
- In the report variables, these will be represented as a JArray (in normal mode) or a semi-colon separated string (in legacy mode)
- All button elements will be automatically disabled, except buttons where the type is 'submit' or 'reset'
- You do not need to include a submit button in your form as Report Magic will add one, if not already present
Here is an example form, which must be saved in a .html file.
<form> <p>This schedule has form element inside a .html file.</p> <p>The HTML file can be chosen in the add/edit dialog on the Schedules page, in the 'Form HTML File' input.</p> <input type="text" name="textinput1" value="val1"></input> <input type="text" name="textinput2" value="val2"></input> <input type="text" name="textinput3" value="val3"></input> <p>This one has no name, and so will not be included:</p> <input type="textinput4"></input> <select name="selectinput1"> <option value="1">1</option> <option value="2">2</option> <option selected value="3">3</option> </select> <select name="multiselect" multiple> <option value="1">1</option> <option value="2">2</option> <option selected value="3">3</option> </select> <p>This button will be disabled:</p> <button>Click me</button> <p>This button will NOT be disabled:</p> <button type="reset">Reset form</button> </form>
Using Form Variables in your Report
For form variables that have been generated by non multi-select inputs, you simply reference the variables using standard macros, e.g. this example prints out the values of the 3 standard text inputs:
[String:value={textinput1}] [String:value={textinput2}] [String:value={textinput3}]
In the HTML, which contains 3 inputs named 'textinput1', 'textinput2', 'textinput3', these become available to use in your report templates as shown above. You may use any macro that can take a text variable.
For the multi-select input type (named 'multiselect' in the previous examples), in legacy mode, simply use the standard List.xxx macros to manipulate the values.
For multi-selects in 'normal' mode (i.e. where you have checked 'Force normal mode' on a Schedule), these will be represented as a JArray. There are various macros that you can use to manipulate a JArray, such as to iterate over the values and perform various actions. The variable will be called the same name as you have set in the 'name' attribute on the select element.
Here are some example macros (for the multi-select called 'multiselect' in the previous example) that demonstrate how you can use the values from the JArray:
// Get the first item from the JArray variable called 'multiselect', output as a list [Json.List: jArray=`{=multiselect}`, jsonPath="$.[0]", storeAs=FirstItemAsList] // Get all the items from the JArray variable, output as a list [Json.List: jArray=`{=multiselect}`, jsonPath="$.[*]", storeAs=AllItems] // Get a count of the items in the JArray variable [Array.Count:value=`{multiselect}`] // Get the first item in the JArray variable, output as a single item (i.e. not a list) [Object.Property:jArray=`{multiselect}`, jsonPath="$.[0]", storeAs=FirstItem] // Iterate over EACH item in the JArray variable, and then just print out the value [ForEach:values={multiselect}, storeAs=Iterator] [String:value={Iterator}] [EndForEach:]
About spreadsheet output
If you have selected to have XLSX output, this can contain automatically-generated tables, macros that produce tabular data or data from any macro followed by a [Table.Save:]
macro. Note that:
- An XLSX file will be produced with one worksheet for relevant macros like
[LogicMonitor.Graph:]
or[File.Table:]
in your report, and each worksheet containing a single table of data - Automatically generated tables (for example
[List.Table:]
will autosave to sheets in the XLSX file if the macro parameter writeToSpreadsheet=true (default behaviour) - For Graph macros, all datapoints are automatically saved to a sheet if the macro parameter writeToSpreadsheet=true (default behaviour)
- As well as using these "automatically generated" tables, you can also save manually generated tables to XLSX, by adding a
[Table.Save:]
macro after each table. Using the parameter saveAsExcelTable=true will save the table in Excel Table format, but you cannot save in this format if the table contains merged cells - no two headings can have the same value. Use the parameter saveAsExcelTable=false if merged cells are present, but this will NOT save in true Excel table format. - To stop any particular macro appearing in a spreadsheet, use the parameter writeToSpreadsheet=false in the individual macro
- To stop all macros of a specific type being shown in a spreadsheet, use a
[Settings:]
macro with writeToSpreadsheet=false for a particular type of macro, for example:
[Settings:LogicMonitor.Graph.writeToSpreadsheet=false]
Worksheets are named automatically. If more than one macro specifies the same tabName, a sheet index is appended to each in the form "<Macrotype> <index>" to differentiate each sheet.
You can also specify your own worksheet names by using the parameter worksheetName in macros. For example:
[LogicMonitor.Graph:writeToSpreadsheet=true,worksheetName=Acme Summary]