Skip to end of banner
Go to start of banner

Copy of TableScriptMacro

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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

  1. To create a script, go to Confluence Administration > Add-ons > cPrime Tools, and click SIL Manager.
  2. Click the silprograms folder and then New > New file
  3. Create a new SIL file and name it, for example, CollectDescendants.sil like in the image below. 




  4. 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;
  5. Supporting script Page DTO is created. This script contains information about the following columns: ID, Author, (page) Title, Created, and Updated.

  6. 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.

  1. To add a TableScriptMacro, go to the necessary Confluence page, click Insert more content, and select Other macros > SIL table.



  2. In the displayed dialog, fill out the necessary fields:
    1. Enter the script name that you created.
    2. Enter the names for the columns.
    3. Enter the input - space key and the page name where you want to display the variables.
    4. 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.



    5. If the transposed checkbox is selected, the table columns will be transposed.



  3. 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.

See also

  • No labels