Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner trim string and label

Mike
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 2, 2019

I am looking to automate a new integration where jira issues are created automatically. The issues have the same text in the description but after the / its a different word. I would like to capture that word and set it as a label. 

Has anyone done anything similar to this?

I believe I would be creating a custom post function to accomplish this. Thanks in advance. 

Jira server version 7.13.x and Scriptrunner is latest

1 answer

1 accepted

1 vote
Answer accepted
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 2, 2019

Here's something I cobbled together in the Script Console that accomplishes what you seek; you should be able to massage it into a post function.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// "issue" is pre-defined in ScriptRunner post script functions, so the following line is unnecessary (just here for testing)
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("BR-13209")
def desc = issue.description
def slash = desc.indexOf("/")
if(slash >= 0)
{
def label = desc.substring(slash + 1).trim()
ComponentAccessor.getComponent(LabelManager).setLabels(user, issue.id, [label].toSet(), false, false)
}

 

Suggest an answer

Log in or Sign up to answer