So far, the examples that were provided were using the custom field type to update the custom field value. This method will not dispatch any Issue Updated
events, and will not write change logs. If you wish to do a fully integrated issue update, you can use the Issue Manager.
Updating using the Issue Manager inside a listener on the “Issue Updated” event will cause an infinite loop! (Fortunately Jira will stop the loop at one point)
Integrating the Issue Manager in your scripts is as follows:
import com.atlassian.jira.event.type.EventDispatchOption; import com.atlassian.jira.component.ComponentAccessor; // Update the issue with the checklist def issueManager = ComponentAccessor.getIssueManager(); issue.setCustomFieldValue(checklistCustomField, existingChecklistValue.toList()); issueManager.updateIssue(event.user, issue, EventDispatchOption.ISSUE_UPDATED, false);
Here is a complete example using 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);