Adjust Summary on Create Issue with "Issue Type" + "Entered Summary" + "Custom Field 1"

At Create Issue I want the Summary to be a combination of a few other fields entered in the Create form. Basically I want "Issue Type" + "Entered Summary" +  "Custom Field 1" etc

I have Script Runner installed and I have managed to get this script to work:

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
issue.summary = "HR Request Test - " + issue.summary;

And this script is placed in the Create function under Post Functions like this:

Creates the issue originally.
Script workflow function : A custom script will be run:
Adjust name to hardcoded "HR Request Test - " + Summary
from inline script.
Re-index an issue to keep indexes in sync with the database.
Fire a Issue Created event that can be processed by the listeners.

In my project I have 4 Issue Types and some custom fields apart from ordinary JIRA native fields

This is a HR Request scenario, so it's like this in pseudo

"Issue Type" + "CF1" + CF2 + "Entered Summary"

"New Headcount;" "Title" + "org-unit" + "Entered Summary"
"Replacement current HC New role;" + "Title New" + "org-unit" + "Entered Summary"
"Replacement current HC Same role;" + "Title" + org-unit" + "Entered Summary"
"Change compensation;" "First name" + "Last name" + "Title" + "Entered Summary"

So the question is how to get Issue Type-value and CF-values into the script


3 answers

1 accepted

0 votes
Answer accepted

Hi, you can read out the value of a customField for example like this:

def customField1 = customFieldManager.getCustomFieldObjects(issue).find { == 'customField1'}

and then use the variable "customField1" in 

issue.summary = "HR Request Test - " + issue.summary + ": " + customField1;

And if you are on the page where you put in your code, you can get some script examples, too.

image2016-10-17 14:29:24.png


Thanks Katya, this works perfect. 

Forgot to mention that we are using JIRA 7.2.1 and Script Runner 4.3.9

I ended up making the the script a bit more complex, since I needed to check and fix summary differently depending on Issue Type. Also since Summary is ALWAYS mandatory and it must be on the Create screen, I added a default according to this KB-article:

This is what my script looks like:

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
// Define Custom fields to use
String FIRSTNAME = "First Name";
String LASTNAME = "Last Name";
String ORGUNIT = "Org-unit"
String TITLE = "Title"
String TITLENEW = "Title New"
//Issue Types
final String CHGCOMP = "Change Compensation";
final String NEWHEAD = "New Headcount";
final String HCNEWROLE = "Replace Current HC New Role";
final String HCSAMEROLE = "Replace Current HC Same Role";
// Get values from the create screen to use
// Get values from First Name, Last Name, Org-unit, Title, Title New entered in the create screen
CustomFieldManager customFieldManager1 = ComponentAccessor.getCustomFieldManager();
CustomField CF1 = customFieldManager1.getCustomFieldObjectByName(FIRSTNAME);
def FIRSTNAMEValue = issue.getCustomFieldValue(CF1);
CustomFieldManager customFieldManager2 = ComponentAccessor.getCustomFieldManager();
CustomField CF2 = customFieldManager2.getCustomFieldObjectByName(LASTNAME);
def LASTNAMEValue = issue.getCustomFieldValue(CF2);
CustomFieldManager customFieldManager3 = ComponentAccessor.getCustomFieldManager();
CustomField CF3 = customFieldManager3.getCustomFieldObjectByName(ORGUNIT);
def ORGUNITValue = issue.getCustomFieldValue(CF3);
CustomFieldManager customFieldManager4 = ComponentAccessor.getCustomFieldManager();
CustomField CF4 = customFieldManager4.getCustomFieldObjectByName(TITLE);
def TITLEValue = issue.getCustomFieldValue(CF4);
CustomFieldManager customFieldManager5 = ComponentAccessor.getCustomFieldManager();
CustomField CF5 = customFieldManager5.getCustomFieldObjectByName(TITLENEW);
def TITLENEWValue = issue.getCustomFieldValue(CF5);
//Default Corrupt Summary if missing Issue Type
issue.summary = ISSUETYPEUSED + "- Missing in WF-" + issue.summary;
issue.summary = ISSUETYPEUSED + " - " + FIRSTNAMEValue + " " + LASTNAMEValue + " - "+ TITLEValue;
issue.summary = ISSUETYPEUSED + " - " + TITLEValue + " - " + ORGUNITValue;
issue.summary = ISSUETYPEUSED + " - " + TITLENEWValue + " - " + ORGUNITValue;
issue.summary = ISSUETYPEUSED + " - " + TITLEValue + " - " + ORGUNITValue;

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 09, 2018 in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

388 views 6 0
Join discussion

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