ScriptRunner for Jira (Server)

You might find Smart Checklist integration with ScripRunner useful for updating checklists using automated scripts. 

Basic Case

However, if the issue has no checklist set yet - it's possible to initiate initial rendering by pushing value to the custom field.

  1. Setup the "Checklists" custom field. Check instructions here "Checklists" Custom Field

ScriptRunner
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.event.type.EventDispatchOption def customFieldManager = ComponentAccessor.getCustomFieldManager() def issueManager = ComponentAccessor.getIssueManager() def issue = issueManager.getIssueObject("PROJ-7") def changeHolder = new DefaultIssueChangeHolder() def String myval = "- 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 user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(); // a text field def textCf = customFieldManager.getCustomFieldObjectByName("Checklists") issue.setCustomFieldValue(textCf, myval) issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

Result


Update/append checklist with post function during a workflow status change

This could be achieved by updating Issue Property with the key com.railsware.SmartChecklist.checklist using REST API Endpoints https://scriptrunner.adaptavist.com/5.6.8/jira/rest-endpoints.html

Set Checklist depending on Custom Field Value after Issue Creation

If you want the specific Checklist appended to your newly created ticket depending on the other Custom field value - you can easily do it by adding Script Runner Post Function to your Create Ticket workflow transition.

Check it out!

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

Result

Implementation flow:

  1. Go to Workflow Editor

  2. Choose "Script Post Function" Script Runner

  3. Choose "Custom Script Post Function"

  4. Add inline Script

  5. Variables checklistProd and checklistStage used for keeping the proper value of the checklist (in text format)

    ScriptRunner

    import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import org.apache.log4j.Level log.setLevel(Level.DEBUG) //Grab necessary Components def cfm = ComponentAccessor.getCustomFieldManager() def optionsManager = ComponentAccessor.getOptionsManager() def cfEnv = cfm.getCustomFieldObjectByName("Environment") def cfEnvtValue = issue.getCustomFieldValue(cfEnv) def cfEnvValueString = cfEnvtValue.toString() def changeHolder = new DefaultIssueChangeHolder() def checklistProd = "- 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 checklistStage = "- Uno\n+ Dos\nx Tres\n~ Cuatro\n" log.info("checklistProd: " + checklistProd) log.info("checklistStage: " + checklistStage) log.info("Environment"+ cfEnvValueString) if (cfEnvValueString == "Production") { //Set custom text field def cfClient = cfm.getCustomFieldObjectByName("Checklists") issue.setCustomFieldValue(cfClient,checklistProd) } else if (cfEnvValueString == "Staging") { //Set custom text field def cfClient = cfm.getCustomFieldObjectByName("Checklists") issue.setCustomFieldValue(cfClient,checklistStage) }



  6. Save the script. IMPORTANT! Make the Post Function is placed as a #1 Step!

Customize checklist visibility by user group/ user role/ ticket type

ScriptRunner can be used for hiding separate UI elements on your Jira tickets depending on different conditions. This way, you can hide Smart Checklist visibility on your Jira instance for specific user groups/ roles/ ticket types.

Here is an example of the implementation flow:

import com.atlassian.jira.ComponentManager import com.atlassian.jira.security.roles.ProjectRoleManager import com.atlassian.jira.component.ComponentAccessor ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class); def usersRoles = projectRoleManager.getProjectRoles(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue.getProjectObject())*.name; return usersRoles.contains("Administrators")

 

Advanced case

Let’s now see more advanced case for validating a transition depending on specific items checked in checklist, and then automatically change issue status when uncheck specific item [DEMO](https://drive.google.com/file/d/1lhxzj6W5LLkrxANLaKcutqcZO5KyytEd/view?usp=sharing ).

Implementation flow:

This is implemented in two steps, first one for validating before transition to new status. Second steps is meant to change status back to “TODO” if the user uncheck the item of checklist.

Transition validator

  1. Go to Workflow Editor

  2. Select Simple scripted validator [ScriptRuner]

  1. Add Condition (script code)

  1. Select Field and Error Message

  1. Publish changes.

Now, the transition to “done” is not possible anymore without having both “RTL Fix” and “Quality Check” checked.

 

Changing status when unchecking item

  1. From ScriptRunner admin page, select Listeners tab and press Create Listener button

  2. Under script section add following

  1. Select Projects to be applied on/Global and Issue Updated as Events

 

  1. Update listener and you are ready to use it.

Create sub-task automatically on all applied checklist items to the issue

This use case allows you to automatically create sub-tasks for each newly added checklist item in an issue. As 'To-Do' items are applied to the issue, sub-tasks will be created for each of them automatically, without any additional manual effort.

 

Implementation flow:

  1. Go to the Jira Administration → Manage apps > SriptRunner

  2. Click on Listeners tab

  3. Click Create Listener

  4. Select Custom listener

  5. Fill in the:

    1. Nam - add name to your listener.

    2. Applied to option - Global or only selected projects.

    3. Events - Issue updated.

    4. Copy Script below.

  6. Click Update and you are ready to use it.

 

Script:

Now every time new checklist item is added or template is applied to the issue, the corresponding sub-task will be automatically created!

 

Set items in DONE when issue is DONE

 

This use case allows you to automatically mark all checklist items to done when issue is resolved or status is changed to done.

 

Implementation flow:

  1. Navigate to Workflow:

    • Go to Jira Settings (⚙️ icon) → IssuesWorkflows.

    • Find the workflow associated with the project and issue type where you want the script to run.

    • Click Edit on the desired workflow.

  2. Edit the Workflow Transition:

    • Identify the transition that moves the issue to "Done" or "Resolved" (usually named "Resolve Issue" or "Done").

    • Click on the transition arrow leading into the "Done" or "Resolved" status.

  3. Add a Post Function:

    • In the transition's Post Functions tab, click Add Post Function.

    • Choose "Custom Script Post Function" (provided by ScriptRunner).

  4. Write the Script:

  1. Go to “Post Functions”

    • make sure that custom script is the last in the post-functions functions

  1. Publish workflow and test