Change Context for an Existing Custom Field Without Losing Old Data
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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
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-62455Getting 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:
Project | Custom Field | Default Value |
---|---|---|
Example Project 1 - No Default | Example List (old context) | (none) |
Example Project 2 - Default | Example 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:
- Assign your new context (with a default value) to "Example Project 2 - Default"
- Navigate to
Issues >> Search issues
- For each possible value entered into the "Example List" custom field
- JQL Search: Project = "Example Project 2 - Default" AND "Example List" = someValue
- Tools >> Bulk Change
- Select all issues, click Next
- Select Edit Issues, click Next
- Tick the box for "Example List" and choose someValue, click Next
- Review changes, then Confirm
Solution 2 - From custom context to default (global) context
This solution applies when you want to change back into the default context:
- 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)
- 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)
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;
- Note down all the IDs and values. Then remove the project-specific Context.
- Stop Jira
- 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.
- 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"
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';
- Start Jira, verify that the values are now displayed in the customfield
Note: If you set a global context for the field, you can still create project-specific contexts for the same field and add existing projects to those. In this case, project-specific contexts will override the global one in selected projects. (from Configuring Custom Field Contexts)