You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hello,
Which code can I use to enter a text string XYZ into the field "Labels"?
Many thanks in advance.
Regards
Leo
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.