Forums

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

ScriptRunner auto update CF on all events

Benjamin Vonlanthen June 13, 2016

I have a problem with my event listener. It is set to 1 project and all events:

Screen Shot 2016-06-13 at 17.09.14.png

CODE:

import org.apache.log4j.Logger
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
MutableIssue myIssue = (MutableIssue) event.issue;
log.info("[UpdateFirelight] Script fired");
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjects(myIssue).find {it.name == 'Firelight'}
if (myIssue.priority.name=='Blocker') {
log.info("[UpdateFirelight] Firelight Red");
myIssue.setCustomFieldValue(customField, "Red")
}
if (myIssue.priority.name=='Critical') {
log.info("[UpdateFirelight] Firelight Yellow");
myIssue.setCustomFieldValue(customField, "Yellow")
}
if (myIssue.priority.name!='Blocker' && myIssue.priority.name!='Critical') {
log.info("[UpdateFirelight] Firelight Green");
myIssue.setCustomFieldValue(customField, "Green")
}
log.info("[UpdateFirelight] Script finished");

 

-------------
I can see that it runs, and without error. But I see no logs nor changes on my custom field. Anyone can help?

As I am really new to script runner, I do not get what I have to change to get it working.


I had a look at http://stackoverflow.com/a/8264451 but can not figure out how to change mine.

1 answer

1 accepted

1 vote
Answer accepted
Vasiliy Zverev
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.
June 13, 2016
Dear @Benjamin Vonlanthen, 
  1. after you set custom filed value you should store it to database using  

    ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(), myIssue, EventDispatchOption.ISSUE_UPDATED, false)
  2. (Optinal ) It seems that swich is more suitable for this script.
Benjamin Vonlanthen June 13, 2016

I got it working with your suggestion. I needed to adjust some other things, but it works now! Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events