Versions Compared

Key

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

You might find Smart Checklist integration with ScripRunner useful for updating checklists using automated scripts. Below you can find the example of adding a checklist to a Jira Issue by means of updating Issue Property with the key com.railsware.SmartChecklist.checklist. 

Note

Since we use Issue Properties as primary memory storage for checklists, it's required to update Issue Property to have checklists updated with any type of automation. Updating "Checklists" Custom Field won't bring the desired result.

Table of Contents

Basic Example

Code

Code Block
languagegroovy
themeMidnight
titleScriptRunner
linenumberstrue
def issueKey = 'SAM-8'
def propertyKey = 'com.railsware.SmartChecklist.checklist'
def propertyValue  = '"- ToDo List\\n+ Checked\\nx Skipped\\n~ In Progress\\n# Another ToDo List\\n- Unchecked\\n> Quote line 1 https://rw.rw\\n> Quote line 2\\n> Quote line 3\\n"'

def result = put('/rest/api/2/issue/' + issueKey + '/properties/' + propertyKey)
        .header('Content-Type', 'application/json')
        .body(propertyValue)
        .asString()
if (result.status == 204) {
    return 'Success'
} else {
    return "${result.status}: ${result.body}"
}

...

Assume that you have a custom field named "Environment" with 2 values: Production/Staging. So you expect that while adding a new issue - you'll have a proper checklist assigned.


Implementation flow

  1. Go To Workflow Editor
  2. Choose "ScriptRunner Post-Function" (Runs a script in a post-function, or a built-in script)
  3. Choose "Run Script" (Run arbitrary code on transition)
  4. Add inline Script
    Image Modified

    Code


    Code Block
    languagegroovy
    themeMidnight
    titleScriptRunner
    linenumberstrue
    //package com.adaptavist.sr.cloud.samples.events
    def issueKey = issue.key
    def newSummary = 'Updated by a script'
    def cfName = 'Environment'
    
    //get custom field of "seelct" type
    def customFields = get('/rest/api/2/field')
            .asObject(List)
            .body
            .findAll { (it as Map).custom } as List<Map>
            
    def cfEnvironmentId = customFields.find { it.name == cfName }?.id
    def cfEnvironment = issue.fields[cfEnvironmentId]
    
    //get custom field
    def environment = cfEnvironment['value'] as String
    
    def propertyKey = 'com.railsware.SmartChecklist.checklist'
    def propertyValue
    
    //compare field values
    if (environment == 'Production') { 
        propertyValue  = '"- ToDo List\\n+ Checked\\nx Skipped\\n~ In Progress\\n# Another ToDo List\\n- Unchecked\\n> Quote line 1 https://rw.rw\\n> Quote line 2\\n> Quote line 3\\n"'
    }else if (environment == 'Staging') { 
        propertyValue  = '"- Uno\\n+ Dos\\nx Tres\\n~ Quatro\\n"'
    }
    logger.info('property' + environment)
    
    def result = put('/rest/api/2/issue/' + issueKey + '/properties/' + propertyKey)
            .header('Content-Type', 'application/json')
            .body(propertyValue)
            .asString()
    if (result.status == 204) {
        return 'Success'
    } else {
        return "${result.status}: ${result.body}"
    }


  5. Variables checklistProd and checklistStage used for keeping the proper value of the checklist (in text format)
  6. Save the script 
    Image Modified
  7. Publish workflow

Result




Insert excerpt
Support
Support
nopaneltrue

...