How do i copy values of two system field into a custom field.

How do i copy values of two system field into a custom field. Say for eg. text field type custom field "Final Status" needs to be updated like this: "<status value> - <resolution value>" for the value of system field Status and Resolution. I cannot do it manually since there are more than 1500 issues in my project, please suggest.

4 answers

0 votes

You'll need a bit of code to do that.  There are a load of add-ons that can do this in varying ways.

If it were up to me, I'd use the Script Runner to create a "scripted field" that concatenates those two together, but that's not quite the same as poking the calculated value into a custom field (with a bit more work, you can still do it with Script Runner)

0 votes
Vasiliy Zverev Community Champion Feb 15, 2016

Here is code example to copy one custom filed value to another. You can modify it and run via Script console provided Script Runner Plugin.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.Project

/**
 * Move date value from one custom field to another
 */

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField dateFrom = customFieldManager.getCustomFieldObjectByName("Дата выдачи согласованного MD.050");
if(dateFrom == null)
        return "field for date from not found"

CustomField dateTo = customFieldManager.getCustomFieldObjectByName("Дата окончания");
if(dateFrom == null)
    return "field for date from not found"

//Loop issues and update
IssueManager issueManager = ComponentAccessor.getIssueManager();
for(Project project: ComponentAccessor.getProjectManager().getProjectObjects())
    for(MutableIssue issue: issueManager.getIssueObjects( issueManager.getIssueIdsForProject())){
        issue.setCustomFieldValue(dateTo, issue.getCustomFieldValue(dateFrom))
        issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(), issue, EventDispatchOption.ISSUE_UPDATED, false)
    }

Hi Pratiyush,

You can do it using "Copy a parsed text to a field" post-function (provided by JIRA Workflow Toolbox plugin) with the following configuration:

Captura de pantalla 2016-02-16 a las 10.38.30.png

Note that:

  • %{00016} is field code for Issue Status
  • %{00028} is field code for Resolution

In order to execute the transition on your 1500 issues at once, I recommend you to do the following:

  1. Create a reflexive temporary transition (same origin and destination status). Let's call it "Temporary Transition"
  2. Add "Copy a parsed text to a field" post-function with the former configuration to "Temporary Transition".
  3. Do a search in JIRA that returns your 1500 issues, and then use bulk change functionality to execute transition "Temporary Transition" in all of them.
  4. Remove "Temporary Transition" from your workflow.

 

Your "Temporary Transition" should look like this:

Captura de pantalla 2016-02-16 a las 10.38.52.png

 

Another possible solution is to use "Write field on issues returned by JQL query" (provided by JIRA Workflow Toolbox plugin) with the following configuration:

Captura de pantalla 2016-02-16 a las 10.59.41.png

Regards,

Fidel

@Fidel Castro Armario

Thanks a lot FIdel for your pointer and it worked indeed !

 

Thanks Nic and Vasiliy for taking time to look after my query, unfortunately we don't have script runner plugin at the moment but certainly your response gives me workaround to use when i wouldn't have workflow toolbox Plugin.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,315 views 12 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you