It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Update Custom Field Value using a “Scriptrunner for Jira” Custom Listener



Hello we are using Jira and are currently evaluating the Plugin "Scriptrunner for Jira" by Adaptavist.

I'd like to create a custom Listener which simply updates the value of a custom field. The field's type is a default textbox, nothing fancy there.

Regarding to the plugin's documentation and various web-searching, I came up with the following code:

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue 
def issue = event.issue as Issue 
MutableIssue issueToUpdate = (MutableIssue) issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find { == 'My CustomField'} 
issueToUpdate.setCustomFieldValue(cf, "myvalue")

The validator does not complain about anything here and the script seems to be executed without any errors. The problem is that the custom field's value is simply not updated. Maybe some of you guys have the missing piece.

Every line seems to be needed as the validator complains otherwise. Thank you in advance for your help.



I just got an answer from Adaptavist that got my code finally working. Please find the working code below:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find { == "My CustomField"}
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), "myvalue"),changeHolder)

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted

What are you putting in the validator part?  You've talked about it, but not mentioned how you've configured it.

Also, can you confirm what type of field "My Custom Field" is - definitely a string?


As this is a custom listener. I don't see any validator part besides the script itself. Please see the screenshot below:



I can confirm that the type of field is a "Text Field (single line)" applied to "Issue type(s):Global (all issues)".


I see one of my colleagues has solved it for us smile

may i know how to update Checkbox = Yes, an issue update.

Kevin, can you please specify which version of Script runner you are using? In the screen shot I see that there is a field for Inline Scripting. I user version 3.0.6 of the ScriptRunner and there is no such field.

I've just ran into the same exact issue... with the specifics that the problem only happens with NextGen Projects.

It works well with classic projects.

Seems to be a bug in the Jira rest API for NextGen projects?

Community showcase
Published in Atlassian Community Events

It is me, Andy B ! a.k.a. FUN MAN ANDY [Community Showcase]

COMMUNITY SHOWCASE – FUN MAN ANDY “Showcases spotlight Atlassian Leaders who make a big impact on our Community. The Atlassian Community Team taps Leaders to share more about themselves and their A...

157 views 10 9
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you