How to get the default value for a multiline custom field using SCRIPT RUNNER? Edited

I am working on a service desk feature request that needs to automatically route certain request types.

Now, In order to allow for the service desk agents to manage business rules via JIRA, I am thinking of using a multiline custom field and set its default value to a CSV value that I should be able to retrieve using ScriptRunner. Since I am using this field mainly to store static data, it is not being used on any issue screens nor will it be ever shared on the screen. The only thing I have to play with is the custom field ID.

My problem is that I am not able to find any information on "how to retrieve a custom field's default value when there is no issue attached to it" So looking for some help to point me in the right direction to be able to do something like this, if it is possible?


1 answer

Hey Anupam,

So you can have multiple configurations for a custom field. Now lets say that you want the default value for the custom field, wtihin the global context. In that case you can use 

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("FreeTextA")
def fieldConfig = ComponentAccessor.fieldConfigSchemeManager.getRelevantConfig(IssueContext.GLOBAL, cf)
def defaultValue = cf.getCustomFieldType().getDefaultValue(fieldConfig)

Now lets say that you have a different defalut value for the same custom field for a specific issue type (let's say Task), then in the above script the fieldConfig will be

def issueTypeId = ComponentAccessor.constantsManager.allIssueTypeObjects.find { == "Task"}.id
def fieldConfig = new IssueContextImpl(null, issueTypeId)

Hope that makes sense ...

Kind regards, Thanos

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,701 views 3 11
Read article

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