Converting Checkboxes fields to Checklist fields using ScriptRunner

With ScriptRunner, you can import values from another custom field, such as Checkboxes, into a Checklist field.

Since Checkboxes custom fields use options as values, we suggest that you transfer the option values to global items. Global items are the successor to options in the Checklist app.


Steps

  1. Create global items with names that correspond to each of the Checkboxes field’s options.

  2. Get the Checklist field that you want to transfer the values to.

    def customFieldManager = ComponentAccessor.getCustomFieldManager(); // Change the field ID to your field's ID def checklistField = customFieldManager.getCustomFieldObject("customfield_10001"); def checklistCFType = (ChecklistCFType) checklistField.getCustomFieldType();

     

  3. Get the Checkboxes field that you want to transfer the values from.

    // Change the field ID to your field's ID def checkboxesField = customFieldManager.getCustomFieldObject("customfield_10002");

     

  4. Fetch the issues that you want to transfer values in. In the below example, we used ScriptRunner to perform a JQL query, but you can fetch the issues using the way that best suits your needs.

    // The JQL query you want to search with final jqlSearch = "Some JQL query" def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser; def searchService = ComponentAccessor.getComponentOfType(SearchService); // Parse the query def parseResult = searchService.parseQuery(user, jqlSearch); if (!parseResult.valid) { log.error('Invalid query') return; } // Perform the query to get the issues def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter) def issues = results.results

     

  5. Loop over each issue and transfer the values from one field to another.

Full example

Here is a full example that imports a Checkboxes custom field into a Checklist custom field in issues obtained using a JQL query.

The script assumes that the Checklist field has global items with names that match exactly with the Checkboxes' options.


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