Script runner listener to update summary

I've been asked to create a script to update the summary of an issue when two custom fields are changed.  The two fields should be added as a pre-fix to the summary if they are not already there.

I looked into doing a post function via the create transition, but this would not cover cases where updates are made after the ticket has been created.

Would a script runner custom listner by the best way to dothis? I am not a scripter  and would greatly appreciate any assistance in acomplishing this.

Field 1, Text field, single line - customFieldId=17241

Field 2, Select list, multiple choice - customFieldId=10942

The code below is what I tried with a post function on create, but results returned as "null/null".

package UpdateIssue
 
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
 
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
 
issue.setSummary(customFieldManager.getCustomFieldObject('customfield_10942').getValue(issue).toString() + "/" + customFieldManager.getCustomFieldObject('customfield_17241').getValue(issue).toString())

1 answer

I fill my summary this way in transition postfunction and its working.

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue;



CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField customLieferant = customFieldManager.getCustomFieldObject(10046L)
CustomField customArtikel = customFieldManager.getCustomFieldObject(10017L)
def lieferant = issue.getCustomFieldValue(customLieferant)
def artikel = issue.getCustomFieldValue(customArtikel)

issue.setSummary("Lieferant : " + lieferant + " || " + "Artikel : " + artikel)

I never used listeners so i cant help you with that at this moment, but maybe the code is already enough.

If you need further assistence tell me

Thanks Stefan,

I ended up using the code below to get the create post function working.  I'll probably trim it down.

Still looking into a listener though.

 

package UpdateIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue; CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); def oldSummary = issue.getSummary(); def rev = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_17241'); def revValue = issue.getCustomFieldValue(rev); def client = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10942'); def clientValue = issue.getCustomFieldValue(client); issue.setSummary(clientValue.toString() + " Rev #" + revValue.toString() + ' ' + oldSummary)

 

 

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

172 views 0 4
Read article

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