Starting with version 4.1.7 of the SIL® Engine, we are introducing the Persistent Variables feature. We are really excited for this new feature which is available in both Power Scripts™ for Jira and Power Scripts™ for Confluence as we know how sought after it is in the Atlassian Community.
PERSISTENT VARIABLES FOR JIRA
A Persistent variable is a value inherently linked to a specific issue or it can be a global value. It is like an extension of the issue fields, or an additional custom field, but internal to SIL®.
Outside the issue context, the persistent variable becomes a global variable which opens up a world of possibilities as global variables can be shared and are accessible from all scripts. Even if instances need to be restarted, persistent variables will remain in the system and will not need to be rewritten.
USAGE IN AN ISSUE CONTEXT
Persistent variables are introduced via the persistent keyword. You cannot have persistent and constant modifiers used on the same variable. A persistent variable is always modifiable.
- The persistent variable is linked to the current issue from the context.
- Persistent variables are only initialized once. Initialization of a persistent variable will be ignored if that variable was already initialized from a previous execution within a particular context.
- A persistent variable is a variable whose value survives the script, making it available in many other scripts under the same name.
USAGE OUTSIDE THE ISSUE CONTEXT
The usage outside the issue context is the same. However, due to the nature of the persistent keyword, the variable becomes a global variable.
There are two helper routines available to ease your work with persistent variables. These routines allow you to set or retrieve the value of a persistent variable from a script that is not in the context of the issue or just to retrieve a global variable:
- getPersistentVar (Simple Issue Language™) — Gets the persistent var, as a string
- setPersistentVar(Simple Issue Language™) — Sets the persistent var, as a string
Need some inspiration for how to use Persistent Variables in Jira? Why not try the following suggestions:
- Create an approval process (approval stored as a persistent variable which can’t be changed through UI.)
- Track time in progress by setting start/stop times as persistent variables then use a scripted field to display the time interval between them.
- Store passwords needed by some script files to sign in easily.
PERSISTENT VARIABLES FOR CONFLUENCE
Persistent Variables are even MORE exciting in Confluence as currently, Confluence does not even have custom fields with which to fabricate the effects of Persistent Variables today.
The Persistent Variable in Confluence can be created:
- in the scope of the Page.
- in the Global scope.
HOW IT WORKS
Creating a Persistent Variable in the Scope of the Page
With the help of certain script, you can add a persistent variable counter to any page to act as a page view counter.
- When you create a copy of the page it will not keep the page view counter.
- If you restart your Confluence instance the page will not keep the page view counter.
- Only admins can see the page count. They can use this to then order the content into “most viewed pages” for readers.
Example – Scope of the Page
- To start with, let’s look into the page counter. With the help of script below, you can initialize, return and then increment it.
- To use the script, you have to add a SIL® Script macro, that executes a SIL® script with persistent page counter.
- That’s it, it returns 0 on your Page.
- If you refresh the page the counter will be incremented because the script is executed again and persistent variable is updated. So, as long as the script is executed again, and again, this persistent variable is updated. It is the one which actually executes in the context of the page.
- This use case can easily be inserted so Confluence page admins can see which pages are popular and which are not. They can then use this information to showcase “trending/ most popular pages” or archive pages that are not relevant anymore. As the saying goes, “persistence is key!” so now you can go forth and reach previously uncharted Jira and Confluence heights thanks to our new Persistent Variables!
Tagged with: confluence, jira, jira admin, persistent variables, scripting
Categorized in: custom fields, Data Integration, Jira Admin, SIL, SIL scripting