Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Version published after converting to the new editor


Excerpt

Enables you to display data that is generated by SIL script in a table, great for reporting.

...

add a button to the page when clicked on which the SIL script is called. 


Note, ButtonScriptMacro is available starting with version 2.0.0. Now, you are able to call any SIL script in your Confluence just with one click or even integrate Confluence and Jira if you have Power Scripts installed for both instances.

Example

Let’s say, you want to display the data generated by SIL script in a tablecreate an Issue in your Jira Project by clicking on the button on the Confluence page.

1. Writing the code in Jira

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


  4. In the CollectDescendantsCreate_Issue.sil file that you created write the following script. It represents how the TableScriptMacro uses the standard variablesscript for your future tickets. This script is stable and retrieves data you have to specify in Confluence. This is an example.
    Then click Check and Save.

    Code Block
    includestring projectKey = "";
    string parentIssueKey = "PageDTO.incl";
    string issueType PageDTO[] dtos= "";
    string 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.
    Image Removed
    issueSummary = "";
    string priority = "";
    string description = "";
    string components = {};
    string dueDate = "";
    string estimate = "";
    string securityLevel = "";
    string fieldMappings = {};
    
    if(isNotNull(getElement(argv, 0)))
      projectKey = getElement(argv, 0);
    
    if(isNotNull(getElement(argv, 1)))
      parentIssueKey = getElement(argv, 1);
      
    if(isNotNull(getElement(argv, 2)))
      issueType = getElement(argv, 2);
      
    if(isNotNull(getElement(argv, 3)))
      issueSummary = getElement(argv, 3);
      
    if(isNotNull(getElement(argv, 4)))
      priority = getElement(argv, 4);
      
    if(isNotNull(getElement(argv, 5)))
      description = getElement(argv, 5);
      
    if(isNotNull(getElement(argv, 6)))
      components = getElement(argv, 6);
      
    if(isNotNull(getElement(argv, 7)))
      dueDate = getElement(argv, 7);
      
    if(isNotNull(getElement(argv, 8)))
      estimate = getElement(argv, 8);
      
    if(isNotNull(getElement(argv, 9)))
      securityLevel = getElement(argv, 9);
      
    if(isNotNull(getElement(argv, 10)))
      fieldMappings = getElement(argv, 10);
    
    createIssue(
                projectKey,
                parentIssueKey,
                issueType,
                issueSummary ,
                priority,
                description,
                components,
                dueDate,
                estimate,
                securityLevel,
                fieldMappings
              );
    


  5. You can find more information about managing your SIL Scripts on the SIL Manager page.


2

...

. Configuring Remote Systems in Confluence

In this case, the Remote Systems option lets you connect Jira with Confluence and call sil scripts from Confluence page. 

  1. To configure it, go to Confluence Administration → Add-ons →  cPrime Tools → Remote Systems and click Add Remote.
  2. You are required to enter the following information:

    Image Added

    Where:

    Name - is the name of the remote system, unique within other remote systems.
    URL - represents the URL (just the base URL, as shown above).
    Username & Password - to care about authentication.
    The timeout is optional, as well as the check result parameters. They control the underlying library responsible for performing REST calls. More information is here.


3. Writing the code in Confluence

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

    Image Added


  4. In the Epic_issue.sil file that you created, you have to specify the necessary parameters and add values for fields of your future issue. Also, it requests to add call routine to push your Sil script in Jira.

    Then click Check and Save.

    Code Block
    string projectKey = "SSTP";
    string parentIssueKey = "";
    string issueType = "Epic";
    string issueSummary = "Development process";
    string priority = "Critical";
    string description = "This issue was created via SIL button";
    string components = {};
    string dueDate = currentDate() + "30d";
    string estimate = "1h 30m";
    string securityLevel = "10000";
    string fieldMappings = {};
    
    string [] args;
    
    args+=projectKey;
    args+=parentIssueKey;
    args+=issueType;
    args+=issueSummary;
    args+=priority;
    args+=description;
    args+=components;
    args+=dueDate;
    args+=estimate;
    args+=securityLevel;
    args+=fieldMappings;
    
    
    call("Test_Jira", "examples/mh_test/create_issue.sil", args);
    



4. Creating a ButtonScriptMacro

So, you have created a scriptthe scripts, but before using itthem, you need to create a TableScriptMacro ButtonScriptMacro and associate the script with it.

  1. To add a TableScriptMacroButtonScriptMacro, go to the necessary Confluence page, click Insert more content, and select Other macros > →  SIL tablebutton.
    Image Removed
    Image Added



  2. In the displayed dialog, fill out the necessary fields:
    1. Enter the name for the button.
    2. Enter the script name that you created .Enter the names for the columnsin Confluence. You have to specify the full path to the program being run (all folders after silprograms if any).
    3. 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.
      Image Removed
      If the transposed checkbox is selected, the table columns will be transposed.
      Image Removedbutton (optional).
    4. Check Reuse if you want the button to remain active after execution.

      Image Added


  3. Click Save to create a TableScriptMacroButtonScriptMacro.
    Image Removed
    Image Added

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.

Note

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.

...



Result

When you click the button, Sil script will be called and an Issue will be created. Depending on settings, the button will stay active or be disabled after use.

Image Added


Info

Note, it is possible to bind one button to one script per page. In other words, you are not able to have several ButtonScriptMacros are connected to the same script on the page.

If you have an issue pressing the button, do a hard page refresh of your browser.


What's next?