Updating items in checklists using ScriptRunner

A popular use case is to change the checklist items depending on the value of another field. For example, you may want to check the value of a particular drop-down and then change the checklist accordingly.

Usually, this kind of manipulation is done using listeners on the Issue Create or Issue Updated events, but can be adapted to other events.

The checklist won’t automatically be updated in the Edit dialog or the issue view, as the user must commit their changes before the Groovy script can react to the event. Real-time updates would require JavaScript code on the webpage, and Checklist for Jira doesn’t currently offer a JavaScript API.


Steps

This example is built with a listener on the Issue Updated event in mind. We will update the checklist’s items based on another field’s value (in this example customfield_10123).

  1. Get the other field’s value.

    def customFieldManager = ComponentAccessor.getCustomFieldManager(); // In this example the issue comes from the listener's event. def issue = event.issue; // Change the field ID to whatever ID your field has def otherField = customFieldManager.getCustomFieldObject("customfield_10123"); // Our field returns a String value. You will probably need to adapt this to your use case. def otherFieldValue = (String) issue.getCustomFieldValue(otherField);

     

  2. Add a guard clause that makes sure the other field has changed and that its value matches what you are looking for as a trigger.

    def otherFieldHasChanged = event.getChangeLog().getRelated("ChildChangeItem").any { it.field == otherField.getName() }; if (!otherFieldHasChanged || otherFieldValue != "Should update checklist") { // Returning here will stop the script and won't update the checklist. return; }

     

  3. Get the checklist field and its items.

    // Change the field ID to whatever ID your field has def checklistField = customFieldManager.getCustomFieldObject("customfield_10001"); def checklistCFType = (ChecklistCFType) checklistField.getCustomFieldType(); Collection<ChecklistItem> items = (Collection<ChecklistItem>) checklistCFType.getValueFromIssue(checklistField, issue);

     

  4. Loop over the items and update the items you wish to update. In this example we want to mark all items with the inProgress status ID as completed by checking them and setting the done status ID.

     

  5. Update the issue with the updated items.

Full example

Here is the full example of updating checklist items based on another field’s value.


SERVER documentation (On Cloud? Go here.)
Have questions? Contact our Service Desk for help anytime.