Hi @Leo Epstein ,
please try the following code :
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.label.Label;
import com.atlassian.jira.issue.label.LabelManager;
import com.atlassian.jira.security.JiraAuthenticationContext;
LabelManager labelManager = ComponentAccessor.getComponentOfType(LabelManager.class);
JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();
Label label = labelManager.addLabel(jiraAuthenticationContext.getLoggedInUser(), issue.getId(), "YOUR_LABEL_HERE", false);
Please let me know if it works.
Fabio
Hi @Fabio Racobaldo _Herzum_ ,
This is exactly what I was looking for!
Just one more question:
Is it possible to make the script so, that it works even while creating a new issue in Jira?
If I try, I get the following message.
Regards, Leo
2022-02-14 16:03:26,786 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed for user 'leo'. View here: https://jira-XXX/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=XXX&descriptorTab=postfunctions&workflowTransition=1&highlight=1 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:90) at com.atlassian.jira.issue.label.LabelManager$addLabel.call(Unknown Source) at com.atlassian.jira.issue.label.LabelManager$addLabel.call(Unknown Source) at Script764.run(Script764.groovy:9)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Leo Epstein ,
try the following scriptedpost function
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.label.Label;
import com.atlassian.jira.issue.label.LabelManager;
import com.atlassian.jira.security.JiraAuthenticationContext;
Issue currentIssue = issue;
LabelManager labelManager = ComponentAccessor.getComponentOfType(LabelManager.class);
JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();
Label label = labelManager.addLabel(jiraAuthenticationContext.getLoggedInUser(), currentIssue.getId(), "YOUR_LABEL_HERE", false);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fabio Racobaldo _Herzum_ ,
Thanks again!
Unfortunately I'm getting the same error "issueId should not be null!".
It seems, that an issue should be created first, and Post Function in Create Transaction cannot set a value of a field... :(
Regards
Leo
2022-02-14 17:24:24,641 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed for user 'leo'. View here: https://jira-XXX/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=XXX&descriptorTab=postfunctions&workflowTransition=1&highlight=1 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:90) at com.atlassian.jira.issue.label.LabelManager$addLabel.call(Unknown Source) at Script773.run(Script773.groovy:11)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Leo Epstein ,
you should place your scripted post function after "Create the issue originally " that's the trick.
Fabio
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.
you're welcome @Leo Epstein
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.