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?

Thanks

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 {it.name == "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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

66 views 0 5
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