Unlock a locked Jira custom field using ScriptRunner

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

This KB article provides changes that are out of the scope of Atlassian Support and, therefore, is provided as-is. The steps are only meant to fix problems within Jira, and not necessarily to be used for any locked fields. Consult with Atlassian support before following the steps listed here. Altering locked system fields can introduce unintended side effects in Jira (such as the inability to pre-populate fields during Issue creation) if unexpected changes are made to default fields, such as adding Translation Text to fields that do not permit this by default.

Info

This KB is a variant of Unlock a locked Jira Software custom field if you do not have Scriptrunner, please follow the other KB for steps on how to do this via the SQL database.

Symptoms

In some cases, you may need to unlock a Locked Jira field:

Cause

These fields are locked to prevent accidental changes which can subsequently break the operation of Jira. Due to some specific problems, you may need to unlock and alter one of those fields, but can't afford a downtime to unlock the field using the database approach.

Resolution

It is possible to Unlock and Lock fields using a Groovy Script, as long as you have Script Runner installed.

(info) To use the scripts below, be sure to adjust the fieldname within "getCustomFieldObjectByName('Epic Status')" from the exemplified "Epic Status" to the field name that you actually want to unlock.

  1. Browse to the Administration section >> Script Runner
  2. In the Console tab you can use the following script to unlock a field:

    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.config.managedconfiguration.ManagedConfigurationItemService
    import com.atlassian.jira.issue.CustomFieldManager
    
    ManagedConfigurationItemService managedConfigurationItemService = ComponentAccessor.getComponent(ManagedConfigurationItemService)
    CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
    
    def cf = customFieldManager.getCustomFieldObjectByName('Epic Status')
    
    if (cf) {
    def mci = managedConfigurationItemService.getManagedCustomField(cf)
    if (mci)
    
    { managedConfigurationItemService.removeManagedConfigurationItem(mci) }
    }
  3. Once you run the script, you should be able to alter the field normally without a restart. Once you finish altering the field, the following script can be used to lock back the field:

    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.config.managedconfiguration.ConfigurationItemAccessLevel
    import com.atlassian.jira.config.managedconfiguration.ManagedConfigurationItemService
    import com.atlassian.jira.issue.CustomFieldManager
    ManagedConfigurationItemService managedConfigurationItemService = ComponentAccessor.getComponent(ManagedConfigurationItemService)
    CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
    
    def cf = customFieldManager.getCustomFieldObjectByName('Epic Status')
    
    if (cf) {
    def mci = managedConfigurationItemService.getManagedCustomField(cf)
    if (mci)
    
    { def managedConfigurationItemBuilder = mci.newBuilder(); def updatedMci = managedConfigurationItemBuilder .setManaged(true) .setConfigurationItemAccessLevel(ConfigurationItemAccessLevel.LOCKED) .build(); managedConfigurationItemService.updateManagedConfigurationItem(updatedMci); }
    }



Last modified on Sep 10, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.