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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Published Apr 19, 2018 in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

366 views 0 6
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