Update issue custom field based on issue change history

Alexey P November 4, 2013

I need to update hundreds of legacy issues with who was developer and test engineer basing on who made a transion. (new ones are updated during transitions)

I added an escalation script in Groovy runner for issues matching JQL query:

status was "In testing" and status != "In testing" and "Test Engineer" is EMPTY

with the following code in Additional issue actions:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.ComponentManager

def componentManager = ComponentManager.getInstance()
def issueManager = componentManager.getIssueManager()
//def customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHistoryManager = ComponentManager.getInstance().getChangeHistoryManager()
def userUtil =  ComponentAccessor.getUserUtil()
def botUser = userUtil.getUserObject("groovybot")

def testEngineer = customFieldManager.getCustomFieldObjectByName("Test Engineer")
def issueChanges = changeHistoryManager.getAllChangeItems(issue)
issueChanges.each { change -> 
  if (change.getField() in ["status"]){
    user = userUtil.getUserByName(change.getUser())
    if (change.getFroms().containsValue("In testing")) {
     	issue.setCustomFieldValue(testEngineer, user)
        issueManager.updateIssue(botUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
    }
  }    
}

When I run this code I get hundreds of Issue <issue key> updated (no action defined)

but none of the issues appears updated

P.S. I don't have enough carma to comment or reply. Sorry

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Sumit Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

try

updateValue(FieldLayoutItem fieldLayoutItem, Issue issue, ModifiedValue modifiedValue, IssueChangeHolder issueChangeHolder)

Also please specify the version of jira you are using

Sumit Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

def changeHolder = new DefaultIssueChangeHolder();

<customfieldobject>.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(<Custom field object>), <Custom Field Value>),changeHolder)

0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

add the following line at after update method

issue.store()

Sumit Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

issue.store() doesn't work for newer versions of Jira(5.0 onwards) if i am not mistaken

0 votes
Sumit Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

*Re-indexing will not be a issues since the changes will be completed in the original issues. Re-indexing will help the values to be updated in the filter.

*Please use Mutable issues when you are trying to update a custom field of an issue instead of a issue

*if nothing is working out, please go for Change Holder and Modified Value

Alexey P November 10, 2013

Renjith, Reindexing did not help.

Sumit, can you provide an example of how to use Mutable issue in my case?

0 votes
Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

You need to reindex the issue also after the update. For all the issues which are already changed, a complete reindex of the JIRA instance should show you the updates.

https://answers.atlassian.com/questions/152955/what-is-the-best-way-to-reindex-an-issue-modified-in-a-script

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events