Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get scriptrunner to update the history of a custom field when I update the value?

Andy Hurley
Contributor
February 24, 2020

I have a custom field for RAG status (BRAG rating) and scripted field for RAID score and I update the RAG status within the scripting for RAID score as follows:

def bragField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "BRAG Rating"}
def fieldConfig = bragField.getRelevantConfig(issue)
def bragValue = optionsManager.getOptions(fieldConfig).getOptionForValue(bragString, null)
bragField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(bragField), bragValue),changeHolder)

This works just fine and I can search and sort by BRAG rating without problems. Now my users want to automate a Trend field based on whether the BRAG rating has gone up, down or remained the same over the past week. I had thought to just look at the history of the BRAG rating field to calculate this but I now notice that there are no history items being stored.

Is there something I need to do in addition to updateValue to cause the history to get updated?

 

1 answer

1 accepted

0 votes
Answer accepted
Ravi Sagar _Sparxsys_
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.
February 24, 2020

Hi @Andy Hurley 

Try with updateIssue().

Ravi

Andy Hurley
Contributor
February 24, 2020

I'm trying but I get 'Cannot find matching method' for both setCustomFieldValue and updateIssue which is why I have always used the updateValue method.

I suspect (I'm not really an OO programmer) that the problem lies with issue not being mutable but I don't know how to go about fixing that.

Bear in mind this code runs in a scripted field and is trying to update another field, not in the context of a transition.

Andy Hurley
Contributor
February 24, 2020

Ah, I found the solution, seems I was working on the right lines but I needed to make a mutable copy of the issue to use in the updates. This did the job:

def MutableIssue mIssue = issueManager. getIssueByCurrentKey(issue.key)

Suggest an answer

Log in or Sign up to answer