Context Variables, Scripts, and Events
This page is about Easy Integrations for Jira Cloud. Using Jira On-Prem? Click the On-Prem button above.
Easy Integrations for Jira supports user scripts in the JavaScript language. You can access various data variables and helper functions in the context to create powerful integrations.
For more information, you can always refer to the axios documentation.
Data Variables and Helper Functions
In the context, you have access to the following data variables and helper functions:
data | Holds event and action execution data |
log(string) | Logs are saved and can be reviewed in Execution Logs. |
callRestApi | Helper function to call any Rest API, based on axios. See request config and  response schema of axios library. |
callJira | Custom function to call Jira Rest APIs, based on axios. Authentication is handled automatically, so do not add authentication headers. Refer to the request config and  response schema of the axios library. |
Helper Utility Functions | |
---|---|
isEqual(string, string) | Checks if 2 strings are equal. |
toLower(string) | Converts |
toUpper(string) | Converts |
includes(array|string, string) | Checks if value is in a collection. If the collection is a string, it's checked for a substring of value. Otherwise, SameValueZero is used for equality comparisons. |
startsWith(string, string) | Checks if |
endsWith(string, string) | Checks if |
trim(string) | Removes leading and trailing whitespace or specified characters from |
You can also utilize any standard JavaScript features in your scripts.
"data" Variable
The "data" variable is attached to the script context. Event data can be accessed by the data.event
object. If the event is issue-related, the "data" includes the issue and can be accessed with data.event.issue
. Action data can be accessed through data.apiData
(see table for more details).
Data type | Example path of the data | Sub objects |
---|---|---|
Webhook event data | data.event | See sub pages for details |
Getting previous action's data Action reference ID is api2 | data.apiData.api1 or data.apiData.api2 | Here is the complete list of action data attributes:
Example usage: data.apiData.api2.responseBody |
Current action's data for custom result script | data.thisAction | Here is the complete list of action data attributes:
|
"callJira" Helper Function
Easy Integrations allows you to call Jira API without dealing with authentication. Authorization is automatically added to the REST API call by the app, and the API is called with app permissions. "callJira" is a wrapper of the axios HTTP library.
The following script example calls issuetype Jira Cloud Rest API and returns the total number of issue types in the system:
var response = await callJira(JSON.stringify({method: 'GET', url: '/rest/api/3/issuetype', data: null, headers: null}));
const responseParsed = JSON.parse(response)
return 'Total issue types: ' + responseParsed?.data?.length
You can call any Jira Rest API that is open to Atlassian Connect App with this method.
"callRestApi" Helper Function
Easy Integrations allows you to call any Rest API. "callRestApi" is a wrapper of the axios HTTP library. "callRestApiRequestParams" is an instance of axios request parameters.
Here's an example of calling a Rest API with authorization and extracting data from the response JSON:
const callRestApiRequestParams = {
method: 'GET', url: 'https://www.example.com/rest/api/2/issue/PROJ-5',
data: null,
headers: null,
auth: {
username: 'XXXXXX',
password: 'XXXXXX'
}
}
const response = await callRestApi(JSON.stringify(callRestApiRequestParams));
const responseParsed = JSON.parse(response)
return 'Issue summary: ' + responseParsed?.data?.fields?.summary
Example: Condition Script
Here's an example of a condition script that logs the issue summary and checks if the issue summary starts with "easy" (case-insensitively):
console.log('data.event.issue.fields.summary is: ' + data.event.issue.fields.summary);
return startsWith(toLower(data.event.issue.fields.summary), 'easy');