Is there a way to set a custom field value with script listener

Hi,

we would like to set a custom field value on an event. At the moment, we already have a script listener sending out email notifications. Can we add setting the field to this listener?

And: If we can, please give a hint on how to set it.

2 answers

Below Groovy example is to set text Custom Field

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
 
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cf1 = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'cf1Name'};
 
def changeHolder = new DefaultIssueChangeHolder();
cf1.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf1), 'newCf1Value'), changeHolder);
 
issue.store();

Does Groovy script do this only after user Submits the form?

Is there any event fired right after a field is modified (new option selected, text filled in) that Script Runner can catch it even before the form submitted?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

691 views 6 13
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