Hi,
I need to set the System field values in JIRA through Groovy code (I have Component fields as "JIRA" and "Confluence" defined). I executed the below code to set the value as "JIRA" (event set for "issue updated"). I do not get any error in the logs but the value is not getting set. can anyone help for the same ? thanks
Code---
@Override
void workflowEvent(IssueEvent event) {
Issue issue = event.getIssue();
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
IssueManager issueManager = componentManager.getIssueManager()
Project project = issue.getProjectObject()
ProjectComponent component = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),"JIRA")
issue.setComponentObjects([component])
issue should be a MutableIssue and you have to store your changes. See my answer here for details. Additionally you could add log messages like
log "component: $component"
to see if everthing is working like you expect.
log.warn or log.debug etc, you probably meant.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh.. yes :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Henning for your pointers, it was mutable issue and storething. By logs i meant that everything was working otherwise a big exception comes. i had removed the log messages before posting on the forum. below is the code which worked for me. once again a big thanks.
Category log = Category.getInstance(test.class)
@Override
void issueUpdated (IssueEvent event) {
log.setLevel(org.apache.log4j.Level.DEBUG)
def groupManager = ComponentAccessor.getGroupManager()
ComponentManager componentManager = ComponentManager.getInstance()
def customFieldManager = componentManager.getCustomFieldManager()
//def watcherManager = ComponentAccessor.getWatcherManager()
MutableIssue issue = event.issue
Project project = issue.getProjectObject()
IssueManager issueManager = componentManager.getIssueManager()
def componentJIRA = componentManager.getProjectComponentManager().findByComponentName(project.getId(),'JIRA')
def componentConfluence = componentManager.getProjectComponentManager().findByComponentName(project.getId(),'Confluence')
def Agroup=issue.getCustomFieldValue( customFieldManager.getCustomFieldObjectByName("Assignment Group"))
try
{
if(Agroup.name.contains("Blocker"))
{
issue.setComponents([componentJIRA.getGenericValue()])
issueManager.updateIssue(null, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
issue.store()
log.debug "Blocker issue"
}
catch(e)
{
issue.setComponents(null)
issueManager.updateIssue(null, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
issue.store()
log.debug "Exception Occured, Blank value is set for Group"
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fine :-) One remark, if you call issueManager.updateIssue() you don't have to call issue.store().
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.