Change Context for an Existing Custom Field Without Losing Old Data

Still need help?

The Atlassian Community is here for you.

Ask the community

Description

In some cases, it may be necessary to change the context for an existing custom field that has been previously populated with data. Doing so may cause a loss of data, requiring that all previous issues are updated after changing the context. This will ensure integrity of historical data by forcing the custom field to update with fresh back-end data, even though nothing will appear to have changed in the JIRA interface.

There is a related bug currently tracked in  JRASERVER-62455 - Getting issue details... STATUS

Example

Scenario

A 'Select List' custom field exists called "Example List" populated with the following values:

  • Value One
  • Value Two
  • Value Three
  • Value Four

It has an existing context with no default value.

The "Example List" field is used in the projects "Example Project 1 - No Default" and "Example Project 2 - Default." This field has been in use on both projects for some time, so both projects have issues with this field populated.

Goal

Change the context for the "Example List" without losing the data previously entered into the custom field for "Example Project 2 - Default."

When we're done, we should have:

ProjectCustom FieldDefault Value
Example Project 1 - No DefaultExample List (old context)(none)
Example Project 2 - DefaultExample List (new context)'Value Three'

In other words, the "Example List" custom field will stay the same, including the existing values from those issues that have already been created, but new issues in the "Example Project 2 - Default" project will have a default value for "Example List."

"Example Project 1 - No Default" will not undergo a change of context for the "Example List" custom field, so no further action will be necessary.


Caution

If you have a test environment, please utilize it for your own testing before making any changes on your live instance of JIRA. Either way, we highly recommend backing up your data before proceeding.

Solution 1 - From custom context to custom context

This solution applies when you are moving between two custom contexts:

  1. Assign your new context (with a default value) to "Example Project 2 - Default"
  2. Navigate to Issues >> Search issues
  3. For each possible value entered into the "Example List" custom field
    1. JQL Search: Project = "Example Project 2 - Default" AND "Example List" = someValue
    2. Tools >> Bulk Change
    3. Select all issues, click Next
    4. Select Edit Issues, click Next
    5. Tick the box for "Example List" and choose someValue, click Next
    6. Review changes, then Confirm
Expand for example of process...

(info) The process for the value "Value One" would look like this:

  1. Issues >> Search Issues
  2. JQL Search: Project = "Example Project 2 - Default" AND "Example List" = "Value One"
  3. Tools >> Bulk Change
  4. Select all issues, click Next
  5. Select Edit Issues, click Next
  6. Tick the box for "Example List" and choose "Value One", click Next
  7. Ensure we're updating all issues from "Value One" to "Value One", then click Confirm


Solution 2 - From custom context to default (global) context

This solution applies when you want to change back into the default context:

  1. First, we have to identify the ID of the Custom field we want to modify. Go to Issues > Custom Fields > Affected Custom Field > Configure and take note of its ID from the URL (e.g., /secure/admin/ConfigureCustomField!default.jspa?customFieldId=10701)
  2. Then we will have to identify the IDs of the current context and the default scheme context, you can also verify and note this information from the URL, when configuring the context (e.g. /secure/admin/ManageConfigurationScheme!default.jspa?fieldConfigSchemeId=11001&customFieldId=10701)
  3. Now on the database you have to retrieve each individual option ID, that is associated with the custom field project-specific context and also from the default context:

    SELECT id,customvalue FROM customfieldoption where customfield = customFieldId AND customfieldconfig = fieldConfigSchemeId;  
  4. Note down all the IDs and values. Then remove the project-specific Context.
  5. Stop Jira
  6. When you delete the context the customOption IDs still remain, however they no longer link to any context, therefore it’s empty on the UI.
  7. If you recreate the context, a new set of IDs will be generated, which do not match the previously existing ones, still resulting in "data loss"
  8. What we aim do to now is to replace the IDs from the custom values of the delete context with equivalent ones from the default context. To achieve this, for EACH customvalue, perform the following:

    update customfieldvalue set stringvalue='DefaultContextcustomvalueID' where stringvalue ='CustomContextcustomvalueID';
  9. Start Jira, verify that the values are now displayed in the customfield


Related Articles:

Configuring custom field contexts

Custom fields with global contexts

Last modified on Mar 21, 2024

Was this helpful?

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