How to set component with string under Script Post-Function -> Additional issue actions

Sandrine Boissel March 21, 2019

I have added a post function to a transition in my workflow to clone an issue. I want to set the component of that new issue in the `Additional issue actions` section but I can't figure out how to do it. I have the string name of the component but it seems you can't set it by string. I imagine there's a pretty straightforward way to do this, but I can't figure it out! 

1 answer

0 votes
Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 26, 2019

Hello Sandrine,

I hope you are having a nice day.

As you can see in this documentation, you can use the following code to set Affects Versions, Fix Versions or Components:

ComponentManager componentManager = ComponentManager.getInstance()
User remoteUser = componentManager.getJiraAuthenticationContext().getUser()
MutableIssue issue = componentManager.getIssueManager().getIssueObject("DTT-1757")
Project project = issue.getProjectObject()
Version version = componentManager.getVersionManager().getVersion(project.getId(), "1.2")
ProjectComponent component = componentManager.getProjectComponentManager().findByComponentName(project.getId(), "MyComponent")
issue.setFixVersions([version])
issue.setComponents([component.getGenericValue()])
 

Map actionParams = EasyMap.build("issue", issue.getGenericValue(), "issueObject", issue, "remoteUser", remoteUser, "dispatchEvent", Boolean.FALSE);
ActionResult aResult = CoreFactory.getActionDispatcher().execute(ActionNames.ISSUE_UPDATE, actionParams);
// check aResult

Let me know if this example helps.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events