Script runner listener to update summary

John Reynolds June 28, 2017

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

0 votes
Stefan Arnold
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2017

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

John Reynolds June 29, 2017

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
TAGS
AUG Leaders

Atlassian Community Events