Apps documentation
Issue Templates for Jira
Cloud Server/Data Center
Issue Templates for Jira

Cloud

Server/Data Center

Documentation
FAQ
Release notes
Articles & Videos
Last updated Sep 20, 2021

Automation

This chapter provides information on how to use the power of Automation and Issue Templates together.

At first, when we think about Jira Automation and ITC cooperation, we may try to find a custom action, which will apply template to an issue according to our rule. That would be the easiest scenario to apply a template to an issue. Unfortunately, due to Jira limitations, it’s not possible to add a new action to Automation.

However, we can get around these restrictions, by using Automation’s Create Issue action with help of the special issue.templates.automation property. What we need you to do is to delegate the job of creating the issue to the Automation and instruct the ITC app to apply the template right after the issue has been created. If you are new to Automation’s Create issue action learn more in official Atlassian documentation.

Configure the action to create a “dummy“ issue with all the required fields for the particular issue type you want to use. Then, expand the More options setting and replace the content with following:

{
    "properties": [{
        "key": "issue.templates.automation",
        "value": {
            "applyTemplate": "TEMPLATE-1"
        }
    }]
}

Above will instruct the ITC app to “applyTemplate“ with issue key equal to TEMPLATE-1.

There are numerous triggers that you can use with Create issue action and apply the template property. We found some of them very interesting and created short videos showing all the configuration steps, which you will find in following sections.

Note
Apply template action is executed right after creating an issue by Automation.

How to schedule creation of issues from templates using Jira Automation?

One of available options to create an issue from template is to use Automation’s Scheduled trigger with Create issue action. Applying template to newly created issue is possible only if you change Create issue action’s properties, as in example below:

{
    "properties": [{
        "key": "issue.templates.automation",
        "value": {
            "applyTemplate": "TEMPLATE-1"
        }
    }]
}

where TEMPLATE-1 is a template key.

Note
Make sure you have changed default Actor in Rule details, otherwise rules won’t work properly.

How to trigger creating issues from template from external tool?

Following example presents steps you need to take in Jira Automation and external tool (here: Postman) to create issues from template.

Jira Automation steps

  1. Create a template in Templates Repository. Use the {{ }} mark to set the variable.
    Note
    By default, variables use [ ] mark. Read more about variables configuration here.
  2. Navigate to Project settings > Automation.
  3. Click Create rule.
    Note
    Make sure you have changed default Actor in Rule details, otherwise rules won’t work properly.
  4. In New trigger, select Incoming webhook.
  5. In Execute this automation rule with select No issue from the webhook.
  6. Click Save.
  7. In Add component, click New action > Create issue.
  8. Select:
  • Project
  • Issue type
  • Choose fields to set (for example: Epic Name).
  1. Type the Summary and complete fields selected in Choose fields to set….
  2. Expand the More list, and in Additional fields type the following formula:
{
    "properties": [{
        "key": "issue.templates.automation", 
        "value": { 
            "applyTemplate": "{{webhookData.templateKey}}",
            "variables" : "{{webhookData.variables}}"
        }
    }]
}
  1. Complete the Rule details and click Save.
  2. Turn on the rule.
  3. Copy the URL from Incoming webhook rule.

Postman steps

  1. Click New and select Request.
  2. Type in the data.
  3. Click Save to Automation.
  4. Select the POST command from the list and enter copied Webhook URL.
  5. In Body section, paste the following formula, where the TemplateKey is the key of your Jira Template and Variables are taken from the Postman:
{ 
  "templateKey": "PMT-602",  
  "variables": "{\"externalSystemName\":\"Postman\",\"externalSystemDescription\":\"Great tool to test REST API, cheers!\"}"  
}
  1. Click Send.
  2. Refresh your Jira Project page.

Result

Issue has been created.

How to pass variables from external system to Automation?

We can pass variables from the webhook using smart values - inside {{ }} mark. We can use the webhookData object, which have access to the body of our webhook. Dot can be used to extract nested properties, however, the last element has to be a string or a number.

Check the following two examples on how to do it:

  • Names of variables are constant

Webhook body:

{
	"templateKey": "PMT-602",
	"variables": {
		"externalSystemName":"Postman",
		"externalSystemDescription":"Great tool to test REST API, cheers!"
	}
}

Additional fields in Automation:

{
    "properties": [{
        "key": "issue.templates.automation",
        "value": {
            "applyTemplate": "{{webhookData.templateKey}}"  
            "variables" : {
              "externalSystemName": "{{webhookData.variables.externalSystemName}}",
              "externalSystemDescription": "{{webhookData.variables.externalSystemDescription}}" 
            }
        }
    }]
}
  • Names of variables can differ

If we don’t know the names of variables, or we want to use different templates and variables with single automation rule, we can’t fix it. Remember that all variables inside {{ }} mark need to be basic, i.e. string or number. We can’t pass object, therefore we will pass stringified JSON. Later, ITC will decode such string.

{
    "properties": [{
        "key": "issue.templates.automation", 
        "value": { 
            "applyTemplate": "{{webhookData.templateKey}}",
            "variables" : "{{webhookData.variables}}"
        }
    }]
}

Additional fields in Automation:

{
    "templateKey": "PMT-602",
    "variables": "{\"externalSystemName\":\"Postman\",\"externalSystemDescription\":\"Great tool to test REST API, cheers!\"}"
}
Note
You can encode any JSON, by executing JSON.stringify(yourJsonObject) in the browser console or any other tool.

If you’re interested in Advanced field editing in Automation, read the official Atlassian documentation.