Button handy | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Button handy | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Panel | ||||||
---|---|---|---|---|---|---|
| ||||||
This page is about Easy Integrations for Jira Cloud. Using Jira On-Prem? Click the On-Prem button above. |
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:
| |||||
Current action's data for custom result script | data.thisAction | Here is the complete list of action data attributes:
|
Panel | ||||||
---|---|---|---|---|---|---|
| ||||||
TIP: To see the data, create a listener, enable the event, add a dummy action, and then perform an action in Jira to trigger the webhook. For example, change an issue's summary for the Issue update event. You can then review the Execution Logs to see the event data, which will help you use the data in your scripts. |
"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:
Code Block |
---|
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:
Code Block | ||
---|---|---|
| ||
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):
Code Block | ||
---|---|---|
| ||
console.log('data.event.issue.fields.summary is: ' + data.event.issue.fields.summary); return startsWith(toLower(data.event.issue.fields.summary), 'easy'); |