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

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?

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted 3 hours ago in United States

Request a Demo

Questions? Want to see a demo of the Atlassian tools? Add a comment below or Send us an email

41 views 2 1
View post

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