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

Helper Utility Functions

isEqual(string, string)

Checks if 2 strings are equal.

toLower(string)

Converts string, as a whole, to lowercase, just like String#toLowerCase.

toUpper(string)

Converts string, as a whole, to uppercase, just like String#toUpperCase.

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 string starts with the given target string.

endsWith(string, string)

Checks if string ends with the given target string.

trim(string)

Removes leading and trailing whitespace or specified characters from string.

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

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:

  • apiStatus – API call data of api2

  • requestUrl – Request URL of api2

  • requestHeaders – Request headers of api2

  • requestMethod – Request method of api2

  • requestBody – Request body of api2

  • requestDate – Request date of api2

  • responseHeaders – Response headers of api2

  • responseBody – Response body of api2

  • responseStatusCode – Response status code of api2

  • duration – API call duration of api2

  • message – Any error message of api2 call

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:

  • requestURL – Request URL of api2

  • requestHeaders – Request headers of api2

  • requestMethod – Request method of api2

  • requestBody – Request body of api2

  • responseBody – Response body of api2

  • responseStatusCode – Response status code of api2

  • duration – API call duration of api2

  • message – Any error message of api2 call

"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');