Heads up! ScriptRunner documentation is moving to docs.adaptavist.com. Adaptavist will keep this site up for a bit, but no future updates to documentation will be published here. ScriptRunner 6.20.0 will be the last release to link to scriptrunner.adaptavist.com for in-app help.

JQL

Scripted fields values, much like any other custom field, have their values updated in the JQL index when an action on the issue causes the issue to be re-indexed. So, for example, creating/updating, or transitioning an issue through standard Jira methods trigger Jira to run a re-index of that issue.

Updating an issue does not cause the scripted fields of linked issues to be re-calculated/updated. If you are editing an issue that has linked issues, only the issue you are editing has its scripted fields updated in the JQL index when you save the update.

There is one exception to this - sub-tasks of an issue are re-indexed when the parent issue is updated but not the other way around. If a sub-task is updated, the parent is not re-indexed.

REST API

How can I access an external REST API with ScriptRunner?

An example script to demonstrate this can be found here in our Adaptavist Library.

We also have an example of talking to the Git hub API which uses this HTTP builder library.

With the above-mentioned HTTP builder library, you may also need to consult the Authentication section depending on the requirements of the ThirdParty API.

Behaviours

How do I get the Service Management Request Type name in behaviours?

From ScriptRunner 6.1.0, you can call the getRequestTypeName method within your behaviour scripts to get the name of the current Service Management Request Type that the user is interacting with.

How do I get the value of the current issue’s custom fields with behaviours when on the edit screen?

Use the underlyingIssue variable in a behaviours script to find the value of current issue’s fields. This variable is available in any behaviour script, however, it will be null on the Create screen because the issue does not exist at that point.

import com.atlassian.jira.component.ComponentAccessor

def myField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().findByName("TextFieldA")
def fieldValue = underlyingIssue?.getCustomFieldValue(myField)
When using the underlyingIssue to retrieve the values of the current issue’s fields those values are obtained from the issue and not the values within the current form.

Script Fragments

How do I find the variables available in the context of where I create my Script Fragments?

Navigate to Script Fragments within ScriptRunner. There is an enable/disable button for the web location finder. Enable this and go to the location where you chose to display your fragment, hover your mouse over the text description inside the desired location, a tooltip shows the context variables for that location.

You can also log out the binding variables for a script fragment which will output to the atlassian-jira.log file using this line:

log.error('binding variables: ' + binding.variables)`

Script Roots

Where are script files stored on Jira Data Center? / Where is the script roots folder on Jira Data Center?

When using ScriptRunner for Jira Data Center, the default location for the script roots is the <shared_home/scripts> directory. This is also the location script files are created by default when using the Script Editor.

The default script roots <shared_home>/scripts, and any custom script root directories created must be accessible to all nodes in the cluster for ScriptRunner features to be able to access the script files.

When you set up Jira Data Center, you are required to create a shared home directory that can be accessed by all nodes in the cluster. Atlassian provides more information on creating this directory.

Mail Handler

How can I catch emails sent to Jira and then create or update issues from that email?

ScriptRunner comes with a custom mail handler feature that lets you run a script when you receive an email into your Jira servers inbound mail server. You can use the Mail Handler feature to trigger when an email comes from specified email addresses using the Catch Email field or have it run the script for all emails received.

This feature is very powerful as you can use the script to perform many actions, including creating an issue based on data within a received email. Please see the guide example here for more information, and you can also refer to our Adaptavist Script Library for further examples of Mail Handler scripts here

Search and Edit Scripts

Is there a way for me to see all my scripts for any given feature in ScriptRunner and search those scripts for specific content?

ScriptRunner provides the Script Registry built-in script; this allows you to see all scripts for each feature in tab format. After running this built-in script you can switch to the feature tab you want to review scripts for, then use the standard browser search tools ctrl + f (windows) or cmd + f (Mac) to find specific content.

Unfortunately, we do not provide a feature that lets you search over all ScriptRunner scripts at once. If you need to frequently search all your scripts, we suggest you change from using inline scripts to using script files instead. Using script files, you can use the operating systems file search tools, or an IDE, to search all your scripts easily. If you use script files, you can also take advantage of version control, so you have better management of changes to your scripts.

Is there a way to bulk edit all or some inline scripts?

ScriptRunner does not provide a method for you to bulk edit all inline scripts. If you are looking to have some form of bulk refactor feature with your ScriptRunner scripts, we suggest you switch to using script files instead of inline scripts wherever possible.

With script files, you can use operating system tools like the Linux sed tool, or open all your scripts in an IDE environment and then run a search/replace using the IDE’s tools. When using files, you can also take advantage of version control allowing you to revert your changes if your bulk edits cause your scripts to break.

Script Editor

When is the issue object available by default in the script editor?

The issue object is available in the following contexts:

  • Post-functions

  • Listeners (as event.issue)

    The issue binding variable is only available for events that contain a single issue object. This means only issue events (excluding issue link events).
  • Behaviours (as underlyingIssue)

    Not available on the Create screen.
  • Scripted Fields

You will have to declare a specific issue object in the following contexts:

  • Script Console

  • Mail Handler

Have questions? Visit the Atlassian Community to connect, share, and learn with other Atlassian users and experts, including Adaptavist staff.

Ask a question about ScriptRunner for JIRA, Bitbucket Server, or Confluence.

Want to learn more? Check out courses on Adaptavist Learn, an online platform to onboard and train new users for Atlassian solutions.