Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Adding labels during issue creation in post function with ScriptRunner

Deleted user August 30, 2016

Hi,

I'm facing a problem where I need to add label to each newly created issue in exact project. Problem is that we don't want to clone workflow, as we are using same in each project.

So I wanted to add post-function in workflow with ScriptRunner script as following

 

import java.util.Set
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.label.*
import com.atlassian.jira.security.JiraAuthenticationContext

LabelManager labelManager = ComponentAccessor.getComponent(LabelManager.class);

JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();

com.atlassian.jira.user.ApplicationUser myUser = jiraAuthenticationContext.getLoggedInUser();

Project myProject = issue.getProjectObject();
if (myProject.getKey() == 'SC')
{
    labelManager.addLabel(myUser, issue.getId(), 'myNewLabel', false);
}

I though that issue is already created during post-function, but i'm getting error

2016-08-31 10:27:55,817 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2016-08-31 10:27:55,817 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
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.call(Unknown Source)
	at Script99.run(Script99.groovy:16)

Thanks

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 31, 2016

Please make sure your post-function is after "Creates the issue originally." post-function, preferably at the end of the list of post-functions.

Deleted user August 31, 2016

yep, solved. thx

TAGS
AUG Leaders

Atlassian Community Events