Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to getCustomFieldObject() via FieldName?

Seth Bennett
Contributor
November 23, 2022

We are preparing to upgrade from Jira Server, which involves going through the Behaviors of Jira Scriptrunner and making sure we're extracting fields via FieldName, rather than using their custom IDs.

This is the original code to populate a dropdown menu:

fieldToHide = getFieldById("customfield_10600")
def customField = customFieldManager.getCustomFieldObject("customfield_10600")
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionsMap = options.findAll {it.value in ['FTP','Physical Media']}.collectEntries {[(it.optionId.toString()): it.value]}
fieldToHide.setFieldOptions(["-1": "None"] + optionsMap)

This is the version that I'm trying to implement:

def getDeliveryMethodField = getFieldByName("Delivery Method")
def deliveryMethodFieldId = getDeliveryMethodField.FieldId

fieldToHide = getFieldByName("Delivery Method")
def customField = customFieldManager.getCustomFieldObject(deliveryMethodFieldId )
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionsMap = options.findAll {it.value in ['FTP','Physical Media']}.collectEntries {[(it.optionId.toString()): it.value]}
fieldToHide.setFieldOptions(["-1": "None"] + optionsMap)

This new code breaks the menu so that it doesn't populate correctly when the code is run, but I don't understand why. If I'm extracting the fieldId of the target, and using that field to target and build the list... shouldn't this work?

1 answer

0 votes
Mohamed Benziane
Community Champion
November 24, 2022

Hi,

The fieldId methode is returning a string but the getCustomFieldObject wait for a long parameter. So you need to make the conversion

Seth Bennett
Contributor
November 28, 2022

I got it working, thanks!

Like Mohamed Benziane likes this

Suggest an answer

Log in or Sign up to answer