TableScriptMacro
Enables you to display data that is generated by SIL script in a table, great for reporting.
Save money to generate a chart by a SIL script. You can use the following data sources: external databases, Jira, and so on. Just think about the possibilities opening here!
Example
Let’s say, you want to display the data generated by SIL script in a table.
1. Writing the code
To create a script, go to Confluence Administration > Add-ons > cPrime Tools, and click SIL Manager.
Click the silprograms folder and then New > New file.Â
Create a new SIL file and name it, for example, CollectDescendants.sil like in the image below.Â
In the CollectDescendants.sil file that you created write the following script. It represents how the TableScriptMacro uses the standard variables.
Then click Check and Save.include "PageDTO.incl"; PageDTO[] dtos; if (size(argv) < 2) { print("space key and page title are not specified"); return dtos; } string spaceKey = argv[0]; string pageTitle = argv[1]; number page = getPage(spaceKey, pageTitle); if (page < 0) { print("space'" + spaceKey + "' has no page '" + pageTitle + "'"); } number[] descendants = getPages(page); for (number pageId in descendants) { PageDTO dto; dto.id = %pageId%.id; dto.author = %pageId%.author; dto.title = %pageId%.title; dto.created = %pageId%.created; dto.updated = %pageId%.updated; dtos += dto; } return dtos;
Supporting script Page DTO is created. This script contains information about the following columns: ID, Author, (page) Title, Created, and Updated.
You can find more information about managing your SIL Scripts on the SIL Manager page.
2. Creating a TableScriptMacro
So, you have created a script, but before using it, you need to create a TableScriptMacro and associate the script with it.
To add a TableScriptMacro, go to the necessary Confluence page, click Insert more content, and select Other macros > SIL table.
In the displayed dialog, fill out the necessary fields:
Enter the script name that you created.
Enter the names for the columns.
Enter the input - space key and the page name where you want to display the variables.
Define the separator. In our case we used comma as a separator, and you can define another symbol. For instance, in cases where a page contains commas in the name, you might want to use period as a separator. For the TableScriptMacro, the separator is applied to both columns and input fields.
If the transposed checkbox is selected, the table columns will be transposed.
Click Save to create a TableScriptMacro.
Summary
You have created CollectDescendants.sil script and a TableScriptMacro that is associated with this script.
Result
Every time you that update a page, the macro will display data generated by the selected SIL script in a table.
Let’s say, you don't have data for the table you created using the TableScriptMacro, and your table is displaying the headers only. To avoid this, you can use the ConditionScriptMacro.