Script to edit summary field in transition in workflow - problem

I am using custom code - on workflow transition - when creating sub-task, code is updating text in summary field.

 The code i am using with scriptrunner

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue
def issueManager = ComponentAccessor.getIssueManager()

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11201")
def cFieldValue = issue.getCustomFieldValue(cField)
def a = cFieldValue.toString()
def x = a.indexOf('[')
def y = a.indexOf(']')
if (cFieldValue != null )
{def newSummary = a[x..y+1] + issue.summary
issue.summary = newSummary}

It should update summary field with text from another custom field. If in custom filed is text [ACC] - Accounting, then when user creates sub-task, field summary should be updated like this [ACC] + summary

The problem i noticed that in filter for an issues, ie. Open issues i am getting this:

(this text [nul] - is dynamic, when i scroll issues it dissapears, or when i click on an issue, but then it show back again.

Any help would be appreciated?

New Bitmap Image.jpg

1 answer

0 votes
Joshua Yamdogo Community Champion Jul 05, 2017

Hi hreich, 

It looks like you have a relatively simple error here. You wrote issue.summary = newSummary. However, this will not allow you to actually  set the summary. You just need to use the setSummary method, e.g. issue.setSummary(newSummary). 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectByName("textField")
def cFieldValue = issue.getCustomFieldValue(cField)
def a = cFieldValue.toString()
def x = a.indexOf('[')
def y = a.indexOf(']')
if (cFieldValue != null )
{def newSummary = a[x..y] + " " + issue.summary
issue.setSummary(newSummary)}

I also think you just need a[x..y]. a[x..y+1] doesn't seem nescessary and throws errors. I added an extra space between the array values and the issue summary, otherwise it will display as [ACC]texthere.

Screen Shot 2017-07-05 at 9.52.47 AM.png

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,897 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot