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

Application_Group August 11, 2017

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

0 votes
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 16, 2017

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
TAGS
AUG Leaders

Atlassian Community Events