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

Convert Customfields: From Checkboxes to Checklist

Scripting offers the ability to import value from another custom field, such as Checkboxes, into the Checklist custom field.

Here is a complete example of importing a Checkboxes custom field into a Checklist. A JQL Query is used to retrieve a list of issues to be updated. Both custom fields must have the same Option Names as this script uses the names to correlate values.

import com.onresolve.scriptrunner.runner.customisers.WithPlugin; import com.atlassian.jira.component.ComponentAccessor; @WithPlugin("com.okapya.jira.checklist") import com.okapya.jira.customfields.*; import com.atlassian.jira.issue.search.SearchProvider import com.atlassian.jira.jql.parser.JqlQueryParser import com.atlassian.jira.web.bean.PagerFilter // Retrieve the Custom Field Type for the Checklist Custom Field def customFieldManager = ComponentAccessor.getCustomFieldManager(); def checklistCustomField = customFieldManager.getCustomFieldObject("customfield_10001"); def checklistCustomFieldType = (ChecklistCFType) checklistCustomField.getCustomFieldType(); // Retrieve the Checkboxes custom field def checkboxesCustomField = customFieldManager.getCustomFieldObject("customfield_10002"); // Execute JQL query to find all issues of Project def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser); def searchProvider = ComponentAccessor.getComponent(SearchProvider); def issueManager = ComponentAccessor.getIssueManager(); def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(); def query = jqlQueryParser.parseQuery("project = PROJ"); // Edit this query to suit your case def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter()); // Update all issues Checklist custom field values results.getIssues().each { documentIssue -> def issue = issueManager.getIssueObject(documentIssue.id); // Retrieve Checkboxes value for Issue def checkboxesValue = (String[]) issue.getCustomFieldValue(checkboxesCustomField); if (checkboxesValue == null) { // "null" value means nothing is checked on the Checkboxes field. Update the checklist with a null value too. checklistCustomFieldType.updateValue(checklistCustomField, issue, null); return; } // Retrieve Checklist value for Issue def checklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField); if (checklistValue == null) { log.error("Checklist Custom Field should have a value. You must create Options with the same name as the Checkboxes options."); return; } // Check items that are listed in Checkboxes value, uncheck those that aren't for (ChecklistItem item : checklistValue) { item.setChecked(checkboxesValue.contains(item.getName())); } checklistCustomFieldType.updateValue(checklistCustomField, issue, checklistValue); }