Hi, I develop this Custom Listener:
package com.meredith.jira.groovy
import org.apache.log4j.Category
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.JiraServiceContext
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.filter.SearchRequestService
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.listeners.reindex.ReindexMessageListener
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
class PutNoMI extends AbstractIssueEventListener {
Category log = Category.getInstance(PutNoMI.class)
//private static final Long FILTER_ID = 10201
ComponentManager cm = ComponentManager.getInstance()
CustomFieldManager cfm = cm.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def authenticationContext = cm.getJiraAuthenticationContext()
JiraServiceContext ctx = new JiraServiceContextImpl(authenticationContext.getUser())
def searchProvider = cm.getSearchProvider()
SearchRequestService searchRequestService = cm.getSearchRequestService()
SearchRequest request = searchRequestService.getFilter(ctx,10201)
IssueManager issueManager = cm.getIssueManager()
public PutNoMI()
{
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "debug statements"
log.info "in constructor"
}
@Override
void workflowEvent(IssueEvent event) {
MutableIssue issue = event.issue as MutableIssue
CustomField workPriority = cfm.getCustomFieldObjects(issue).find {it.name == "Comment MI"}
//MODIFICAT
def fieldConfig = workPriority.getRelevantConfig(issue)
def newValue = optionsManager.getOptions(fieldConfig)?.find{it.value == "No"}
//log.info "Value to change CommentMI in next issue: ${newValue}"
def results = getSearchResults(request)
results.getIssues().eachWithIndex { iss , i ->
issue = issueManager.getIssueObject(iss.id)
log.info "Processing ${issue.key}"
i += 1
def commentMI = issue.getCustomFieldValue(workPriority)
log.info "Actual Value of CommentMI: ${commentMI}"
log.info "GO, changin commentMI..."
issue.setCustomFieldValue(workPriority, newValue)
def newCurrentIssuePriority = issue.getCustomFieldValue(workPriority)
log.info "CHANGED! New value of commentMI in this issue: ${newCurrentIssuePriority}"
}
}
SearchResults getSearchResults(SearchRequest sr) {
return searchProvider.search(sr.getQuery(), authenticationContext.getUser(), PagerFilter.getUnlimitedFilter())
}
}
But I have problem, my logs shows that the custom Field is changed but when I enter to issue, the custom field 'Comment MI' still the same..
These are my logs:
2013-04-09 12:35:50,449 http-bio-8080-exec-7 ERROR admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [groovy.canned.utils.ConditionUtils] javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method contains() on null object
2013-04-09 12:35:50,479 http-bio-8080-exec-7 ERROR admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [groovy.canned.utils.ConditionUtils] javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method contains() on null object
2013-04-09 12:35:50,486 http-bio-8080-exec-7 DEBUG admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] debug statements
2013-04-09 12:35:50,486 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] in constructor
2013-04-09 12:35:50,534 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] Processing PI-1067
2013-04-09 12:35:50,535 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] Actual Value of CommentMI: Yes
2013-04-09 12:35:50,535 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] GO, changin commentMI...
2013-04-09 12:35:50,535 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] CHANGED! New value of commentMI in this issue: No
2013-04-09 12:35:50,567 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] Processing PI-1066
2013-04-09 12:35:50,569 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] Actual Value of CommentMI: Yes
2013-04-09 12:35:50,569 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] GO, changin commentMI...
2013-04-09 12:35:50,569 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] CHANGED! New value of commentMI in this issue: No
2013-04-09 12:35:50,571 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] Processing PI-1062
2013-04-09 12:35:50,574 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] Actual Value of CommentMI: Yes
2013-04-09 12:35:50,574 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] GO, changin commentMI...
2013-04-09 12:35:50,574 http-bio-8080-exec-7 INFO admin 755x2398x1 ucrbou 192.94.163.146 /rest/api/2/issue/PI-1067/comment [meredith.jira.groovy.PutNoMI] CHANGED! New value of commentMI in this issue: No
2013-04-09 12:35:50,995 com.atlassian.mywork.client.reliability.DefaultUnreliableWorker:thread-1 WARN admin 629x57x1 boasfh 192.94.163.146 /secure/admin/util/JellyRunner.jspa [apache.commons.httpclient.HttpMethodBase] Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
2013-04-09 12:35:51,825 com.atlassian.mywork.client.reliability.DefaultUnreliableWorker:thread-1 WARN support 629x57x1 boasfh 192.94.163.146 /secure/admin/util/JellyRunner.jspa [apache.commons.httpclient.HttpMethodBase] Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Any idea of my problem?