JIRA DC Scriptrunner - change the name of a custom field context

294 Views Asked by At

JIRA Data Center v9.x

using Scriptrunner, I can get the context name of a custom field

CustomField cField = customFieldManager.getCustomFieldObject(customFieldId)
List<FieldConfigScheme> contexts = cField.getConfigurationSchemes() 
if ( contexts.size() == 1 ){
    FieldConfigScheme tmpContext = contexts[0]
    log.warn("tmpContext :: ${tmpContext.name}")
}

I need to be able to change the context name! The FieldConfigScheme class does not have a set...

I have looked through all the related classes I can find, and done Google searches, all to no avail.

is there a way to change the custom field context name using Scriptrunner?

That did the trick This is what I got working!

def allCFIDs = customFieldManager.getCustomFieldObjects().collect({return it.getId()})
    allCFIDs.each { customFieldId ->
        CustomField cField = 
            customFieldManager.getCustomFieldObject(customFieldId)
        List<FieldConfigScheme> contexts = cField.getConfigurationSchemes() 
        FieldConfigScheme tmpContext = contexts[0]
        if ( tmpContext.name.contains("Fred") ){
            def newname = tmpContext.name + " Flintstone"
            log.warn("Rename Context:: ${tmpContext.name}    to ::  ${newname}")
            def schemeData = new SchemeBuilder( tmpContext )
            schemeData.setName( newname )
            def updatedScheme = schemeData.toFieldConfigScheme()
            fieldConfigSchemeManager.updateFieldConfigScheme( updatedScheme )
    }
}
0

There are 0 best solutions below