---
title: "Context variables, scripts, and events"
canonical: "https://support.appfire.com/space/EIFJC/10125347/Context%20variables%2C%20scripts%2C%20and%20events"
format: markdown
---
> Macro (aura-html)

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, refer to the [axios documentation](https://axios-http.com/docs/req_config).

## 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](https://appfire.atlassian.net/wiki/spaces/EIFJC/pages/10125341). |
| **callRestApi** | Helper function to call any Rest API, based on axios. See [request config](https://axios-http.com/docs/req_config) and  [response schema](https://axios-http.com/docs/res_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](https://axios-http.com/docs/req_config) and  [response schema](https://axios-http.com/docs/res_schema) of the axios library. |

| ### **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** |
| --- | --- | --- |
| Webhook event data | data.event | See sub pages for details |
| Getting previous action's data<br>Action reference ID is **api2** | data.apiData.api1<br>or<br>data.apiData.api2 | Here is the complete list of action data attributes:<br>- **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<br>> ℹ️ **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:<br>- **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<br>> ℹ️ **Example usage:** data.thisAction.responseBody |

> 📝 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](https://appfire.atlassian.net/wiki/spaces/EIFJC/pages/10125341) 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:

```javascript
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:

```javascript
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):

```javascript
console.log('data.event.issue.fields.summary is: ' + data.event.issue.fields.summary);
return startsWith(toLower(data.event.issue.fields.summary), 'easy');
```