Versions Compared

Key

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

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

Note

Updating Be careful, using the Issue Manager inside a listener on the “Issue Updated” event 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 in your scripts is as follows:.

Code Block
languagejava
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.component.ComponentAccessor;

//
Update the issue with the checklist
def issueManager = ComponentAccessor.getIssueManager();

You then update the checklist data in the issue.

Code Block
languagejava
issue.setCustomFieldValue(checklistCustomField, existingChecklistValue.toList());

And finally use the Issue Manager to finish the job.

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

...

Here Following is a complete example using that uses the Issue Manager:

Code Block
languagejava
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);