Does anybody know how to store a custom field's Display Name?

Hello everyone, I’m trying to write a Groovy script using Scriptrunner that will store the Display Name in the Service Desk Portal and then add that Display Name to the value stored in the field and I can’t get it to work.

At the moment this thing is falling apart in several places (I suspect that I’m also not retrieving the Custom Field’s ID correctly) the main issue that I’m having is that I can’t find any method by which to retrieve the Display Name value. I know that it must be getting stored somewhere but I can’t find any documentation that goes into it.

Here’s my code:

//Action to run on is Create (1). Effect of this is that it will run on the
//workflow transition between an issue being created and it going to Waiting for Support

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor;

//def issue = event.issue as Issue;
MutableIssue issue = issue
def userManager = ComponentAccessor.getUserManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def fieldManager = ComponentAccessor.getFieldManager();
def userSearch = userManager.getUserByName(“eric.price”);

//Defines a list containing all of the available custom fields of an issue
def customFields = customFieldManager.getCustomFieldObjects(issue)

customFields.each { customField ->

//Saves the ID field of the current field
def fieldId = customFieldManager.getCustomFieldObject("customfield_id");

//Saves the display name of a custom field 
String displayName = getCustomFieldValue(customField).displayName;

//Saves the data currently being held in the field
String customFieldData = issue.getCustomFieldValue(customField);

//Combines the display name and the field data
def newFieldData = displayName + ": " + customFieldData;

//Sets the custom field data as the combined entry defined earlier
issue.setCustomFieldValue(customField, newFieldData)


I’m doing this in order to cut down on the amount of Custom Fields that I need to generate as Service Desk is only a small part of our JIRA integration and these fields appear to be defined globally. I’m hoping that by doing this I’ll be able to use a small amount of generic Custom Fields for a number of Request Types in Service Desk.

Would greatly appreciate any help that anybody is able to give with this.