/
Apply Template using automation/integration tools

Apply Template using automation/integration tools

Add Smart Checklist Templates using the Template ID to your issues via different tools available in Jira - ScripRunner for Jira, Automation for Jira, JMWE.

 

Contents 👇🏼

☝🏼 NOTE: For issues with multiple checklist tabs, all Public API calls will only interact with the Default Checklist tab, and any templates will be imported into that tab.

Steps on how to apply the Smart Checklist Template via Automation for Jira

💡HINT: This is just an example of a use case with Issue created trigger. You can select any other available trigger based on your needs.

  1. Create a personal access token

    1. Navigate to User icon → Profile → Personal Access Tokens → Create Token

      image-20240212-154345.png
    2. Copy token value

  2. Go to Project Settings → Project Automation → click Create rule: (or go to Administration → System → Automation rules → click Create rule: )

    image-20240212-154212.png

     

  3. Create a trigger

    1. Choose Issue created

    2. Save

      image-20240213-125247.png

       

  4. Add component - New action

    image-20240213-125359.png

     

    1. Choose Send web request as the first action.

      image-20240213-125435.png
    2. Fill in the fields with the following values:

Webhook URL

http://Jira_base_URL/rest/railsware/1.0/checklist?issueKey={{issue.key}}

Webhook URL

http://Jira_base_URL/rest/railsware/1.0/checklist?issueKey={{issue.key}}

Headers

Header Name: Authorization
Header Value: Bearer <token> (replace <token> with the token obtained in Step 1)

Example: Bearer NDQ51zY0NzQ4NjUz...GdnIjoZbDOvd6TVslhWXJX

HTTP method

GET

Webhook body

Empty

Wait for Response

Check this option

image-20240213-142250.png

c. Save

  1. Add component - New action

    image-20240213-125919.png

     

    1. Choose Send web request as the second action

      image-20240213-125946.png
    2. Fill in the fields with the following values:

Webhook URL

http://Jira_base_URL/rest/railsware/1.0/checklist/{{webhookResponse.body.checklists.get(0).checklistId}}/template/${templateId}

Where ${templateId} should be replaced by the actual Smart Checklist template id

Webhook URL

http://Jira_base_URL/rest/railsware/1.0/checklist/{{webhookResponse.body.checklists.get(0).checklistId}}/template/${templateId}

Where ${templateId} should be replaced by the actual Smart Checklist template id

Headers

 

Authorization

Bearer + token (mentioned in step 1)

HTTP method

POST

Webhook body

Empty

Wait for Response

Don’t check this option

☝🏼NOTE: You can find the Template ID by going to Issue → Smart Checklist → 3 dots menu → Manage Templates → Expand the Template you are looking for → Copy the Template ID ✅

Or going to Jira Administration → Manage apps → Smart Checklist Settings → Templates tab → Find needed template → Click on the Template you are looking for → Copy the Template ID ✅

  • image-20240212-161048.png

Check out more about Templates IDs here →Use Templates in Automation tools

image-20240213-142327.png

c. Save

  1. Name your new Automation and Turn it on

    image-20240213-130543.png

You're done! Now every time an issue is created, the proper template will be added to your Smart Checklist 🎉

Steps on how to apply the Smart Checklist template via ScriptRunner

  1. Go to Jira Administration → ScriptRunner → Console

    image-20240213-145801.png
  2. Add the following script:

import com.atlassian.jira.component.ComponentAccessor import com.atlassian.sal.api.UrlMode import com.atlassian.sal.api.net.Request import com.atlassian.sal.api.net.TrustedRequestFactory import groovy.json.JsonSlurper import groovyx.net.http.URIBuilder def testIssueKey = "TEST-1" def templateId = 10 class SmartChecklistAPI { def trustedRequestFactory = ComponentAccessor.getOSGiComponentInstanceOfType(TrustedRequestFactory.class) def applicationProperties = ComponentAccessor.getApplicationProperties() long getChecklistId(String issueKey) { def url = applicationProperties.getString("jira.baseurl") + '/rest/railsware/1.0/checklist?issueKey=' + issueKey def checklistResponse = sendGetRequest(url) assert checklistResponse instanceof Map assert checklistResponse.checklists instanceof List assert checklistResponse.checklists.get(0) instanceof Map return (long) checklistResponse.checklists.get(0).get("checklistId") } void applyTemplate(Long checklistId, Long templateId) { def url = applicationProperties.getString("jira.baseurl") + '/rest/railsware/1.0/checklist/' + checklistId + '/template/' + templateId sendPostRequest(url) } private Object sendGetRequest(String url) { def request = trustedRequestFactory.createTrustedRequest(Request.MethodType.GET, url) def host = new URIBuilder(url).host request.addTrustedTokenAuthentication(host) def responseBody = request.execute() return new JsonSlurper().parseText(responseBody) } private void sendPostRequest(String url) { def request = trustedRequestFactory.createTrustedRequest(Request.MethodType.POST, url) def host = new URIBuilder(url).host request.addTrustedTokenAuthentication(host) request.execute() } } def checklistAPI = new SmartChecklistAPI() def checklistId = checklistAPI.getChecklistId(testIssueKey) checklistAPI.applyTemplate(checklistId, templateId)

Where testIssueKey and templateId should be changed accordingly.

  1. Click Run

💡HINT: This is just an example of a use case using Console. You can also use this script in other ScriptRunner places, like Workflows etc. In such a case replace value of testIssueKey with issue.key to get a reference of the current issue.

Steps on how to apply the Smart Checklist template via JMWE

  1. Navigate to Jira Administration → Manage apps → Jira Misc Workflow Extensions Settings → Select Groovy console

    image-20240213-152244.png
  2. Add the following script:

import com.atlassian.jira.component.ComponentAccessor import com.atlassian.sal.api.UrlMode import com.atlassian.sal.api.net.Request import com.atlassian.sal.api.net.TrustedRequestFactory import groovy.json.JsonSlurper import groovyx.net.http.URIBuilder def testIssueKey = "TEST-1" def templateId = 10 class SmartChecklistAPI { def trustedRequestFactory = ComponentAccessor.getOSGiComponentInstanceOfType(TrustedRequestFactory.class) def applicationProperties = ComponentAccessor.getApplicationProperties() long getChecklistId(String issueKey) { def url = applicationProperties.getString("jira.baseurl") + '/rest/railsware/1.0/checklist?issueKey=' + issueKey def checklistResponse = sendGetRequest(url) assert checklistResponse instanceof Map assert checklistResponse.checklists instanceof List assert checklistResponse.checklists.get(0) instanceof Map return (long) checklistResponse.checklists.get(0).get("checklistId") } void applyTemplate(Long checklistId, Long templateId) { def url = applicationProperties.getString("jira.baseurl") + '/rest/railsware/1.0/checklist/' + checklistId + '/template/' + templateId sendPostRequest(url) } private Object sendGetRequest(String url) { def request = trustedRequestFactory.createTrustedRequest(Request.MethodType.GET, url) def host = new URIBuilder(url).host request.addTrustedTokenAuthentication(host) def responseBody = request.execute() return new JsonSlurper().parseText(responseBody) } private void sendPostRequest(String url) { def request = trustedRequestFactory.createTrustedRequest(Request.MethodType.POST, url) def host = new URIBuilder(url).host request.addTrustedTokenAuthentication(host) request.execute() } } def checklistAPI = new SmartChecklistAPI() def checklistId = checklistAPI.getChecklistId(testIssueKey) checklistAPI.applyTemplate(checklistId, templateId)

Where testIssueKey and templateId should be changed accordingly.

  1. Click the Test Groovy script button

    image-20240213-152433.png
  2. Enter Issue Key where you want to apply template → Click Test

    image-20240213-152552.png
  3. You will see a message 🚀

    image-20240213-152659.png

💡HINT: This is just an example of a use case using Groovy Console. You can also use this script in other JMWE places, like JMWE Workflow extentions etc. In such a case replace value of testIssueKey with issue.key to get a reference of the current issue.

 

 

 

Related content