Custom Text field with merged data from Issuekey & Summary

We are required to have Customfield (text) to contain data from Issuekey & Summary in an Issue

Such merging & filling into a customfield, is possible by any scripting or available plugin ?

Appreciate your feedback

1 answer

KCF - Kepler Custom Fields. The script is smth like:

return key + " " + summary;

There are others as well ....

HTH,

Radu

With ScriptRunner plugin and Groovy script set as Custom Listener (that can trigger on event like "Issue Created", "Issue Updated", "Issue Resolved", etc):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def issue = event.issue;
def currentIssueKey = issue.toString();
def summaryFieldValue = issue.getSummary().toString();
def newFieldValue = currentIssueKey + ' ' + summaryFieldValue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def changeHolder = new DefaultIssueChangeHolder();
def customTextField = customFieldManager.getCustomFieldObjectByName("Custom Text Field");
customTextField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customTextField), newFieldValue), changeHolder);

Thanks for the script, Radu. There are errors as in below, while just checking in Script console. Any thoughts, please ?IssueKey+Summary_Error_1.jpg

This is groovy, not SIL over / KCF (with its simpler scripting language).

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder


def issue = event.issue;
def currentIssueKey = issue.toString();
def summaryFieldValue = issue.getSummary().toString();
def newFieldValue = currentIssueKey + ' ' + summaryFieldValue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def changeHolder = new DefaultIssueChangeHolder();
def customTextField = customFieldManager.getCustomFieldObjectByName("KeySummary");
customTextField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customTextField), newFieldValue), changeHolder);

Customfield (Text) created as - KeySummary
Added this script as Script in in-line of Post-function of Create issue in a workflow

Created an issue, getting the errors as follows

2017-04-10 09:30:24,986 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-04-10 09:30:24,986 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
groovy.lang.MissingPropertyException: No such property: event for class: Script316
at Script316.run(Script316.groovy:6)

Do we need to declare - event ?

 

Custom field created as - KeySummary

Script updated into postfunction of workflow as below with name of above mentioned customfield

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder


def issue = event.issue;
def currentIssueKey = issue.toString();
def summaryFieldValue = issue.getSummary().toString();
def newFieldValue = currentIssueKey + ' ' + summaryFieldValue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def changeHolder = new DefaultIssueChangeHolder();
def customTextField = customFieldManager.getCustomFieldObjectByName("KeySummary");
customTextField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customTextField), newFieldValue), changeHolder);

But getting error as below

 

2017-04-10 09:30:24,986 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-04-10 09:30:24,986 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
groovy.lang.MissingPropertyException: No such property: event for class: Script316
 at Script316.run(Script316.groovy:6)

 

Do we need to define - event..?

Any suggestions to correct above errors, please ?

Thanks much for help

This script won't work as post function but will work as Custom Listener - you need to have ScriptRunner plugin installed in order for this to work.

Please go here (of course change "your_jira_instance.com" to address of your Jira):

https://your_jira_instance.com/plugins/servlet/scriptrunner/builtin?section=script_listeners

On presented screen you will have an option to create new "Custom listener".

While creating listener you will be able to define what events it will be triggering on - see official documentation I linked above for details.

I tested above code and it works with Custom Listener.

If you want to use above code as post function you can just comment or remove this line:

def issue = event.issue;

I tested this as "Script Post-Function" --> "Custom script post-function" and it works.

 

It worked as expected in Create & Transition Steps. Thanks much 

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 Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

846 views 3 12
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