I have been trying to come up with a way to set a component on an Issue based on the setting of a single select list at the time of issue creation. I am very new to groovy code and have gotten to where my script executes without errors, but it does not actually set the component. I am hoping that someone can give me a hand to identify what I'm doing wrong.
I am doing this to help with routing incoming issues into a support intake project to particular component leads.
import com.atlassian.jira.bc.project.component.ProjectComponent import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.project.Project def projectComponentManager = ComponentAccessor.getProjectComponentManager() MutableIssue issue = issue def cfSrcId = 12800 CustomFieldManager cManager = ComponentAccessor.getCustomFieldManager() CustomField srcField = cManager.getCustomFieldObject(cfSrcId) def cfrt = issue.getCustomFieldValue(srcField)?.value Project project = issue.getProjectObject() ProjectComponent component = null if(cfrt == "Analytics"){ component = projectComponentManager.findByComponentName(project.getId(), "Analytics") } else if(cfrt == "LMM/Volta"){ component = projectComponentManager.findByComponentName(project.getId(),"LMM") } else if(cfrt == "Openstack"){ component = projectComponentManager.findByComponentName(project.getId(),"Openstack") } else if(cfrt == "Account Management"){ component = projectComponentManager.findByComponentName(project.getId(),"Account Management") } else if(cfrt == "App Support"){ component = projectComponentManager.findByComponentName(project.getId(),"App Support") } else if(cfrt == "Capacity"){ component = projectComponentManager.findByComponentName(project.getId(),"Capacity") } else if(cfrt == "OBS"){ component = projectComponentManager.findByComponentName(project.getId(),"OBS") } else if(cfrt == "SDN"){ component = projectComponentManager.findByComponentName(project.getId(),"SDN") } else if(cfrt == "SRE"){ component = projectComponentManager.findByComponentName(project.getId(),"SRE") } else if(cfrt == "Underlay Network"){ component = projectComponentManager.findByComponentName(project.getId(),"Underlay Network") } if (component) { issue.setComponentObjects([component]) }
Community moderators have prevented the ability to post new answers.
You may as well use
issue.setComponentObjects ([component])
rather than the outdated genericValue method.
For a select list you want:
def cfrt = issue.getCustomFieldValue(srcField)?.value
Thank you for the tip Jamie, I've modified the script with the two recommendations, changing the component.getGenericValue lines and the variable definition. No errors in the logs still, but the components aren't being touched. Is there a problem because I am doing this in the Create transition? (Code above modded to match)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Which position is the function in the create transition? Definitely no errors in atlassian-jira.log?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Step 2, right after "Create issue originally" No error when I chose Analytics (first if). I see I've got a different syntax for the else if's and those do error. "" file: /data/home/projira/scripts/cloudfire_component.groovy groovy.lang.MissingPropertyException: No such property: ComponentAccessor for class: cloudfire_component at cloudfire_component.run(cloudfire_component.groovy:25) "" Side effect of my hacking code together as a newbie I expect. I'm either doing something wrong in the Analytics "if" or I've missed an import statement somewhere, possibly both.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
blatant log error resolved (was missing "import com.atlassian.jira.component.ComponentAccessor") no more errors using both variations of getting the component, still not setting it though, heh.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've modified it a bit to remove some of the redundancy: https://bitbucket.org/snippets/Adaptavist/Mbdpo I would suggest you change it so that it simply finds a known component and sets that. If that works you can move on to the select list stuff.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That certainly is more crisp than my patchwork attempt (THANK YOU). As a test, I chopped the entire if/else serice (everything below Project Component component = null) and replaced it with: component = projectComponentManager.findByComponentName(project.getId(), "LMM") issue.setComponentObjects([component]) It's still not setting a component on create, I verified no one had removed the component and that the logging is quiet. Is it possible that this isn't functioning due to being in the create transition post-functions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The code shown above is not functioning, both in the create post-function and in transition post functions.
I am uncertain what the problems were before, we may have had an index problem which was complicating testing.
Thank you @Jamie Echlin [Adaptavist] for all of the insights you provided.
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.