Versions Compared

Key

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


Excerpt
hiddentrue

 Post function to automatically create a Confluence page within a Jira workflow.

Easy Integrations comes with a handy post function in order to create Confluence pages via Jira workflow transitions. 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 the Add post function link.
  • Locate Create Confluence Page using a template page post function and click Add button.

Then configure REST service parameters.

Table of Contents
outlinetrue

Post Function Name 

You can create a name for 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 can only return true statement. However, you can type your script and return true; to execute REST, or return false; to not execute.

Below there is a sample code of how you can type your own script.


Condition code example:

Code Block
languagegroovy
firstline1
titleCondition
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)

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 on separate lines as described in screenshot.
  • Request Body: Type json request body. You can use dynamic parameters here as well
  • Parameters: Define all of your dynamic parameters here using Groovy Script. You can add static values as well as the dynamic values of fields/custom fields in the Jira issue. Here are some sample usages:

    Code Block
    languagegroovy
    firstline1
    linenumberstrue
    def parameters = [:]
    
    parameters["assignee"] = issue.assignee
    parameters["reporter"] = issue.reporter
    
    def userManager = ComponentAccessor.getUserManager()
    parameters["userDisplayName"] = userManager.getUserByName("someUserName").getDisplayName()
    
    def cf = customFieldManager.getCustomFieldObject("customfield_xxxxx")
    def price = issue.getCustomFieldValue(cf)
    parameters["price"] = (null != price) ? price : "No price defined"
    
    return parameters

    For more details and utils for parameter assigning see Parameters usage examples.
    Also see ComponentAccessor, UserIssue 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 the Credentials section will be listed.

Below is an example:


Post Operations

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

  • First click on the Update custom field checkbox.
  • The custom field drop down menu will be 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 the custom field with the body itself, just leave this text box 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 for 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 a long time for the spinner. So, it may be wise to enable async if your REST service responds slowly.

  2. 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. 
Info

There is a scheduled task named Easy Integrations for Jira - Async Rest Caller Scheduled Task which runs every 2 minutes, checks for those REST calls and then executes. 




View of Post Function

Please do not forget to publish the 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 you 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) will not be updated successfully since store Update change history and store the issue in the database post function 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 function.