Forums

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

Remove part of text from summary field

AJ
Contributor
August 26, 2022

Hi, I've been doing jira for a while, but only recently started using scriptrunner. I created a script that adds the value of another single select custom field (city) to description. The problem is that I need a transition that allows me to change city, and I don't know how to remove the previous entry from the description. If I use my previous postfunction it adds another city to description:

example tittle # cityA
->
example tittle # cityA # cityB
Is anyone able to guide me with some solution?

1 answer

1 accepted

2 votes
Answer accepted
AJ
Contributor
August 26, 2022

I found a solution, maybe it will be useful to someone.


Long JobFieldId = 11111L
Long CityFieldId = 11112L

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField JobField = customFieldManager.getCustomFieldObject(JobFieldId)
CustomField CityField = customFieldManager.getCustomFieldObject(CityFieldId)

IssueManager issueManager = ComponentAccessor.getIssueManager()
String JobValue = issue.getCustomFieldValue(JobField)


String MyIssue = issue.getSummary().toString()
int hash = MyIssue.indexOf(" # ");
if(hash > 0)

MyIssue = MyIssue.substring(0,hash)


if (JobValue!=null && (JobValue == ("Things to do")))
{
issue.setSummary(MyIssue + " # " + issue.getCustomFieldValue(CityField))
}

else
{
issue.setSummary(MyIssue);
}

 

Suggest an answer

Log in or Sign up to answer