This documentation is for version 4.x. For the latest documentation, click here

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Current »

So far, all the provided examples were using the custom field type to update the checklist. However, this method will not dispatch any Issue Updated event and will not write change logs. If you wish to do a fully integrated issue update, you need to use the Issue Manager.

Be careful, using the Issue Manager inside an event listener will cause an infinite loop! Fortunately Jira will stop the loop at one point.

First, you need get a hold of the Issue Manager.

import com.atlassian.jira.component.ComponentAccessor;
def issueManager = ComponentAccessor.getIssueManager();

You then update the checklist data in the issue.

issue.setCustomFieldValue(checklistCustomField, existingChecklistValue.toList());

And finally use the Issue Manager to finish the job.

import com.atlassian.jira.event.type.EventDispatchOption;
issueManager.updateIssue(event.user, issue, EventDispatchOption.ISSUE_UPDATED, false);

Following is a complete example that uses the Issue Manager:

import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
@WithPlugin("com.okapya.jira.checklist")
import com.okapya.jira.customfields.*;

// Retrieve the Custom Field Type for the Checklist Custom Field
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def checklistCustomField = customFieldManager.getCustomFieldObject("customfield_10013");
def checklistCustomFieldType = (ChecklistCFType) checklistCustomField.getCustomFieldType();

// Check all items
def issue = (MutableIssue) event.issue;
def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField);
for (ChecklistItem item : existingChecklistValue) {
    item.setChecked(true);
}

// Update the issue with the checklist
def issueManager = ComponentAccessor.getIssueManager();
issue.setCustomFieldValue(checklistCustomField, existingChecklistValue.toList());
issueManager.updateIssue(event.user, issue, EventDispatchOption.ISSUE_UPDATED, false);
  • No labels