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

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

490 views 3 18
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