How to switch from a Live field to a Snapshot field?


Table of contents


1. Create a new field

First of all, you should know that it's not possible to convert a Live field into a Snapshot field. These two field types are too different to switch from one type to the other (see The different field types). 

So you have to create a new field from scratch and configure it according to the following requirements:

  • The template (i.e. the displayed value) of both fields must be similar
  • The query in both fields must return the same results set (excluding the key used in the Live field) 

(info) This article only explains how to switch from a Live field to a Snapshot field and not the other way around. Switching from a Snapshot field to a Live field is not relevant since the Snapshot field data cannot be used as a key in the Live field.


2. Move data from the Live field to the Snapshot field

There are two possible methods to achieve this action:

  1. The first one is to create a transition in your workflow and add an Elements Connect post-function that will be executed from a bulk operation. It will be necessary to execute the bulk operation several times, as many times as there are different statuses in your workflow.
  2. The second method consists in executing a script from the Scriptrunner for Jira application to update the Connect field in all issues returned by a JQL query.

The advantage of the first method is that it doesn't require any third party application to work. However, it's more time-consuming because it requires performing the same action several times to process each workflow status separately.
As for the second method, it's faster as it doesn't require repeating any action, but Scriptrunner for Jira must be installed on your Jira instance.

a. Use an Elements Connect post-function

The first method consists in using the Elements Connect post-function called Copy display to issue field.

First, edit the relevant project workflow and create a dummy transition, as follows:

Then add the Copy display to issue field post-function to this transition:

When configuring this post-function, select the Live field as source and the Snapshot field as target:

Once this is done, perform a bulk operation and edit all the relevant issues:

Select the Transition Issues operation:

And run the transition we previously configured:

(warning) This bulk operation might need to be done several times because it's per status. If the issues are in different statuses, repeat the above.

b. Run a Groovy script from Scriptrunner for Jira

The second method consists in running a Groovy script from Scriptrunner for Jira.

Here is the script to run:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
   
def pluginAccessor = ComponentAccessor.getPluginAccessor();
def plugin = pluginAccessor.getPlugin("com.valiantys.jira.plugins.SQLFeed");

def serviceValueClass = plugin.getClassLoader().loadClass("com.valiantys.nfeed.api.IFieldValueService");
def fieldValueService = ComponentAccessor.getOSGiComponentInstanceOfType(serviceValueClass);

def serviceDisplayClass = plugin.getClassLoader().loadClass("com.valiantys.nfeed.api.IFieldDisplayService");
def fieldDisplayService = ComponentAccessor.getOSGiComponentInstanceOfType(serviceDisplayClass);
   
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
   
def query = jqlQueryParser.parseQuery("YOUR_JQL_QUERY")
def liveFieldId = "customfield_XXXXX"
def snapshotFieldID = "customfield_YYYYY"
   
def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
   
log.warn("Total issues: ${results.total}")

results.getResults().each { issue ->
    String liveFieldValue = "";
    Object liveFieldResult = fieldDisplayService.getDisplayResult(issue.key, liveFieldId);    
	liveFieldValue = liveFieldResult.getDisplay();
    
    fieldValueService.setFieldValue(issue.key, snapshotFieldID, liveFieldValue);
}

(info) In this script, you have to replace:

  • YOUR_JQL_QUERY with a valid JQL query returning the issues to be updated
  • customfield_XXXXX with your Live field ID
  • customfield_YYYYY with your Snapshot field ID

Run this script and check that the Snapshot field has been correctly updated.