Custom Text field with merged data from Issuekey & Summary

CST JIRA Confluence Admin April 5, 2017

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

0 votes
Radu Dumitriu
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.
April 6, 2017

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

return key + " " + summary;

There are others as well ....

HTH,

Radu

Ron Gates April 6, 2017

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);
CST JIRA Confluence Admin April 6, 2017

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

Radu Dumitriu
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.
April 7, 2017

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

CST JIRA Confluence Admin April 9, 2017
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 ?

 

CST JIRA Confluence Admin April 10, 2017

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..?

CST JIRA Confluence Admin April 10, 2017

Any suggestions to correct above errors, please ?

Thanks much for help

Ron Gates April 11, 2017

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.

Ron Gates April 11, 2017

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.

CST JIRA Confluence Admin April 11, 2017

 

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

Suggest an answer

Log in or Sign up to answer