Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

With

Button handy
blankfalse
color#EBECF0
nameCloud
linkhttps://appfire.atlassian.net/wiki/spaces/EIFJC/overview
width84
Button handy
blankfalse
color#0052CC
nameData Center
linkhttps://appfire.atlassian.net/wiki/spaces/EI4J/overview?homepageId=11206659
width105

Panel
panelIconIdatlassian-info
panelIcon:info:
bgColor#F4F5F7

This page is about Easy Integrations for Jira DC. Using Jira Cloud? Click the Cloud button above.

This guide explains how to configure Easy Integration's Issue Listeners you can integrate your Jira with your internal/external systems by calling REST services accordingly. In this page, you will explore how to define a listener and configure the REST service. to call external REST services when specific issue events occur in your Jira projects. By following these steps, you can integrate your internal and external systems to automate workflows and improve data exchange.

On this page:

Table of Contents
minLevel1
maxLevel6
outlinefalse
styledefault
typelist
printabletrue

Accessing listeners

Listeners can be accessed in the within Easy Integration's admin UI (Jira admin cog icon > Manage apps > Easy Integrations Menu > Listeners (EI)).  Image Removed

...

 On this page, you can find all the listeners that you already defined. Also, you can;This page displays all existing listeners. You can perform the following actions:

  1. Create a new listener.

  2. Edit an existing listener.

  3. Delete an existing

...

  1. listener.

...

Step 1: Create a new listener

  1. Click the Add New Listener button.

  2. Fill

...

  1. in the listener details:

...

  1. Screenshot 2024-08-14 at 14.49.03.pngImage Added

    ...

      • Name: Assign a descriptive name

    ...

      • for your listener.

      • Projects: Select the specific projects

    ...

      • where you want to

    ...

      • monitor issue events

    ...

      • . You can also choose

    ...

      • All Projects

    ...

      • .

    ...

      • Issue Types

    ...

      • : Select the issue

    ...

      • types you want to listen to

    ...

      • , or choose All Issue Types.

      • Issue Events: Select one or more issue events that trigger the listener.

    Step 2: Add a condition

    In this part, you can add a condition for the listener. 

    ...

    By default, it only has only the return true statement, which means that the listener will execute the REST call. However, you can type your own script in order to programmatically add a condition to execute the REST service or not.

    Image Removed
    Below , is a sample code snippet for a condition which that checks the logged-in user should be the reporter of the issue:

    Execute Code

    Code Block
    languagegroovy
    titleExecute Code
    linenumberstrue
    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.user.ApplicationUser
    
    ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
    log.info("current user:" + currentUser.username)
    def reporter = issue.reporter.username
    log.info("reporter: " + reporter)
    return reporter.equals(currentUser.username)

    ...

    Step 3: Fill in REST service details

    In this part, REST details (URL, method, headers, body, credential, etc..) are filledcreated.

    Image Removed

    1. URL – The endpoint of the REST service. You can type any dynamic parameter here using double curly braces. (

    ...

    1. for example, http://mycompany.com/api/book/{{bookId}} assuming bookId is defined

    ...

    1. within the Parameters section which is described below.

      image-20240814-115545.pngImage Added
    2. Method – Select the

    ...

    1. HTTP Method (GET, POST, PUT, DELETE).

    2. Headers – Define your HTTP header key/value sets in separate lines

    ...

    1. .

    2. Request Body – Type the JSON request body—you can use dynamic parameters here as well. Note that if send attachments is selected, the request body must be in a form-data format where key-value pairs can be defined. Check the code block below:

    Request Body form-data

    Code Block
    table_name = incident 
    table_sys_id = d71f7935c0a8016700802b64c67c11c6
    1. Parameters – Define all your dynamic parameters

    ...

    1. . You can add static values as well as the dynamic values of fields/custom fields in the

    ...

    1. Jira issue.

    ...

    1. Below are some sample usages

    ...

    1. .

    2. Choose the authorization type. Currently, BASIC Authentication is supported.

    ...

    1. If you choose the Basic Authorization Type, the credential

    ...

    1. will become active

    ...

    1. and the credentials you defined in the Credentials

    ...

    1.  section will be listed.

    ...

    Headers code example;

    ...

    :

    Headers

    true
    linenumbers
    Code Block
    Accept=application/json

    Request body Body code example;

    ...

    :

    ...

    Request Body

    true
    linenumbers
    Code Block
    {
       "item"  : "{{productName}}",
       "price" : "{{price}}",
       "date"  : "{{date}}",
       "item"  : "{{productName}}",
       "owner" : "{{user.displayName}}"
    }

    ...

    Parameters code example;

    ...

    :

    Parameters

    linenumbers
    Code Block
    true
    assignee    = $issue.assignee or {{issue.assignee}}
    reporter    = {{issue.reporter}}
    date        = $issue.created
    formattedDate = $DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format($issue.created)
    productName = $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_11100'))
    price       = $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_11102'))
    displayName = $user.displayName
    userDisplayName = $ComponentAccessor.getUserManager().getUserByName("someUser").getDisplayName() // you can also use ComponentAccessor
    comment     = $comment // this is the comment that is passed through the transition

    For more details on parameter assigning and utils for parameter assigning see Parameters usage examples 
    Also , see the Parameters Usage Examples page.
    Also, see ComponentAccessorUserIssue and Status API and Status API for all properties and methods.

    Step 4: Run asynchronously

    ...

    (Optional)

    In this section, you can enable async Async to execute the REST service asynchronously. There are a couple of reasons why you may want to execute asynchronously.

    ...

    • Executing synchronously makes the user wait for the transition longer than usual. If the

    ...

    • REST service host responds late or there is a connection

    ...

    • timeout between the

    ...

    • Jira server and the host, the

    ...

    • user will wait for the spinner for a

    ...

    • long time. So, it may be wise to enable async if your REST service responds

    ...

    • slowly.

    • Some issue parameters may wait for calculation or reindexing. Some plugins may work in the background to populate the actual result of a custom field and you may want to use that value. 

    There is a scheduled task named Easy Integrations for JIRA Jira - Async Rest Caller Sched

    ...

    .

    Step 5: Update custom field (Optional)

    In this section, you can configure will find out how to update a custom field based on a value in the REST response.

    ...

    1. First

    ...

    1. , tick the Updatecustom field checkbox.

    ...

    1. Select the custom field that you want to update from the drop-down menu.

    2. Type

    ...

    1. the JSONPath accordingly to select the value. If the result is not JSON and you want to update a custom field with the body itself, just leave this textbox empty.

    See the JSONPath examples page for samples.

    Image Removed

    1. Click the checkbox if you want to update any custom field
    2. A select custom field which will be update
    3. Type jsonpath for custom field

    ...

    Step 5: Send attachments

    In this section, you will find out how to send attachments with REST calls.

    ...

    1. First, tick the Send Attachments checkbox.

    2. Write the name of the form-data parameter name that contains attachments. For instance, in Jira REST API for attachments, this name must be file, and in ServiceNow REST API, this name must be uploadFile.

    3. Write a groovy script that returns attachments. These attachments will be sent with the REST call. If the script is empty, then all attachments will be sent.

    Send Attachments

    Code Block
    languagegroovy
    import com.atlassian.jira.component.ComponentAccessor;
    import com.atlassian.jira.issue.AttachmentManager;
    
    AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager();
    def attachments = attachmentManager.getAttachments(issue);
    return attachments;