Skip to end of banner
Go to start of banner

REST Service Caller Post Function

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 18 Next »


Easy Integration comes with a handy post function in order to create Confluence pages via JIRA workflow transition. The issue's field/custom field values can be used to generate Confluence pages from templates.

Here are the steps:

  • Go to the desired transition of your workflow, switch to Post functions tab, and click on Add post function link.
  • Locate Create Confluence Page using a template page post function and click Add button.


Then configure REST service parameters.


The parts of REST Caller Post Function;

Post Function Name 

You can give a name to your post function. 


Condition

In this section, you can give a decision to execute REST according to the result of Groovy script.
By default, it has only return true statement. However, you can type your script and return true; to execute REST, or return false; not to execute
Below, there is a sample code on how you can type your own script.


Condition code example;

Condition
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)

REST Service Details

In this section, REST details (URL, method, headers, body, credential, ..) are filled.

  • URL: The endpoint of the REST service. You can type any dynamic parameter here using double curly braces. (e.g. http://mycompany.com/api/book/{{bookId}} assuming bookId is defined in Parameters section which is described below)
  • Method: Select Http Method (GET, POST, PUT, DELETE)
  • Headers: Define your HTTP header key/value sets in separate lines as described in screen-shot
  • Request Body: Type json request body. You can use dynamic parameters here as well
  • Parameters: Define all your dynamic parameters here. You can add static values as well as the dynamic values of fields/custom fields in JIRA issue. Here are some sample usages:

    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 and utils for parameter assigning see Parameters usage examples 
    Also see ComponentAccessorUserIssue and Status API for all properties and methods.

  • Authorization Type: Choose authorization type. Currently BASIC Authentication is supported.
  • Credential: If you choose any Authorization Type, this option becomes active, and the credentials you defined in Credentials section are listed.

Below is the sample screenshots


Post operations

In this section, you can configure to update a custom field based on a value in REST response

  • First click on Update custom field checkbox
  • Custom field drop down is displayed, select the one you want to update
  • Type jsonpath accordingly to select the value. If the result is not json and you want to update custom field with the body itself, just leave this textbox empty.

See jsonpath examples page for jsonpath samples.


Run asynchronously?

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

  1. Executing synchronously makes user wait for the transition longer than usual. If the host of the REST service responds late or there is a connection time out between JIRA server and the host, the users waits for the spinner a lot. So, it may be wise to enable async if your REST service responds slow

  2. Some issue parameters may wait for calculation or reindexing. Some plugins may work 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 - Async Rest Caller Scheduled Task which runs every 2 minutes and checks for those REST calls, then executes. 




View of Post Function

Please do not forget to publish workflow to see it in action.


Order of the REST Service Caller post function

The order of the REST Service Caller post function is very important depending on what we want to do. 

If the REST Service Caller post function is BEFORE the "Update change history for an issue and store the issue in the database." post function

  • $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_10123')) call returns the old value of customfield_10123
  • $transientIssue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_10123')) call returns the new value of customfield_10123
  • If the Update custom field is selected, the custom field(s) would be updated successfully.

If the REST Service Caller post function is AFTER the "Update change history for an issue and store the issue in the database." post function

  • $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_10123')) call returns the new value of customfield_10123
  • If Update custom field is selected, the custom field(s) would not be updated successfully since store Update change history and store the issue in the database post fuction is already executed.


So, if you want to use the new value of a field (which is changed via transition screen) and also you want to update a custom field value, you should use $transitionIssue and place the REST Caller Service post function before the Update change history and store the issue in the database post fuction.

  • No labels