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
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the script, Radu. There are errors as in below, while just checking in Script console. Any thoughts, please ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is groovy, not SIL over / KCF (with its simpler scripting language).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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..?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any suggestions to correct above errors, please ?
Thanks much for help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It worked as expected in Create & Transition Steps. Thanks much
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.