Researching various solutions, and drawing a blank.
I want to add a component to an issue as it is created (for why, see below, maybe there are two questions in one) and added a post function that executes the following
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
MutableIssue issue = issue
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def componentA = projectComponentManager.findByComponentNameCaseInSensitive('Jira Access Request')
issue.setComponent(componentA)
No errors are generated, yet the components field remains empty.
Any idea why this update is not being saved?
* As to the why
I want to assign an issue to a fixed user. I could add this user in each of the steps but then users have a habit of moving so don't want to edit the workflow each time. Opted for option to assign to Developer Lead (i.e. component lead or project lead if component not set). If user leaves they simply update the component lead. Any other suggestions?
I believe you also need to use the IssueManager.updateIssue() method to save the changes. I haven't tested this code, but this might work for you:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
MutableIssue issue = issue
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def componentA = projectComponentManager.findByComponentNameCaseInSensitive('Jira Access Request')
issue.setComponent(componentA)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks so much for this! I have been trying to figure out how to do this for weeks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Roy Chapman
Try to save your changer with issueManager.
As for your second question, i dont clearly understand last part, but you can set as assignee component lead or project lead like in my example
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
MutableIssue issue = issue
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def issueManager = ComponentAccessor.getIssueManager()
def componentA = projectComponentManager.findByComponentNameCaseInSensitive('Jira Access Request')
issue.setComponent(componentA)
def componentLead = componentA.first().getComponentLead()
def projectLead = issue.getProjectObject().getProjectLead()
if (componentLead){
issue.setAssignee(componentLead)
} else {
issue.setAssignee(projectLead)
}
issueManager.updateIssue(issue.getReporter(), issue, EventDispatchOption.DO_NOT_DISPATCH, false)
Hope it helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mark,
Thanks. I tried Alex's version first and this worked. Bu thanks for your suggestion as well. Greatly appreciated.
Regarding the question on assigning I am already using Developer lead (which feeds from the component lead). I was wondering if there was a better way (components could be removed, for example). We can assign to project lead, reporter and a random member of a role. Would be nice to be more specific without having to edit the workflow each time.
Thanks again. It really makes my life easier to get such a prompt response.
Roy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.