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 _Catworkx_ ,
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)
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);
Hi @Fabio Racobaldo _Catworkx_ ,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...
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)
It looks like you're new here. Sign in or register to get started.