Hi,
I use Script Runner's postfunction to create some sub-tasks during a transition. Is there a way to set new individual labels to a few of the sub-tasks? I tried "issue.label = somelabel;" at the additional issue actions, but it won't work.
Regards
Ja
You should use LabelManager.addLabel() to add labels like this:
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager) labelManager.addLabel(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue.getId(), "label", false)
I use JIRA 7.1.4 and Script Runner 4.3.1 so i had to change it to
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager) labelManager.addLabel(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue.getId(), "Label", false)
But it still doesn't work, my log says
/secure/WorkflowUIDispatcher.jspa [c.o.s.jira.wo rkflow.ScriptWorkflowFunction] Script function failed on issue: DEMO-525, actionId: 221, file: null com.atlassian.jira.util.dbc.Assertions$NullArgumentException: issueId should not be null! at com.atlassian.jira.util.dbc.Assertions.notNull(Assertions.java:25) at com.atlassian.jira.issue.label.DefaultLabelManager.addLabel(DefaultLabelManager.java:104) at com.atlassian.jira.issue.label.LabelManager$addLabel$0.call(Unknown Source) at Script1382.run(Script1382.groovy:10)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this on the issue create transition? It looks like issue.getId() is null when you pass it to the add label method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should place postfunction after issue creation function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When subtask is created you can get created issue into CreateResult variable. Use it to get issue id. Could you provide code to create a subtask?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the problem is the "additional code" section runs before the issue is actually created.
You could try putting Vasily's code in a "doAfterCreate" closure, eg:
doAfterCreate { // add label }
it may work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ja,
Combining the feedback you got from the guys above, try
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.label.LabelManager doAfterCreate = { def labelManager = ComponentAccessor.getComponent(LabelManager) labelManager.addLabel(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue.getId(), "Label", false) }
If it still doesn't work please attach the error you get
regards
Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool. The doAfterCreate closure is not documented yet but it will be in the next documentation update (which will be soon)
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.