Forums

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

Setting default value for a custom text field

Melanie Pasztor
Contributor
January 9, 2020

Hello!

Having trouble setting the default form value for a custom multi-line text field when creating an issue, using scriptrunner behaviours. It works for system description field as per a scriptrunner example, but no clear way to achieve the same for a custom description field. Also total lack of information on underlyingissue class in the documentation. 

 

def descField = getFieldById("customfield_#####")

def defaultValue = """1. Lorum Ipsum
2. random text
3. blah blah
4. Profit!
""".replaceAll(/ /, '')

if (!descField.getValue()) {
descField.setFormValue(defaultValue)
}

Tried setting it to check if the custom text field is empty, but does not work, likely not knowing for where. Hence the underlyingissue class.   

It would be 'if (!underlyingIssue?.description)' for a system description field, so what would be the equivalent for a custom text field?  

I tried 'if (!underlyingIssue?.getFieldById("customfield_#####"))' and ' if (!underlyingIssue?.descField)' and other variations to no avail, but spits the error that it does not exist for the class. 

Appreciate any help with this, or pointing towards a better method. 

 

1 answer

1 accepted

2 votes
Answer accepted
Patrick
Contributor
January 9, 2020

Use getCustomFieldValue:

def descField = getFieldById("customfield_10084")
def descFieldObj = customFieldManager.getCustomFieldObject("customfield_10084")

def defaultValue = """1. Lorum Ipsum
2. random text
3. blah blah
4. Profit!
""".replaceAll(/ /, '')

if (!underlyingIssue?.getCustomFieldValue(descFieldObj)) {
descField.setFormValue(defaultValue)
}

 

Regards

Patrick

Melanie Pasztor
Contributor
January 9, 2020

Ah, thank you! :)

Ranganath HV Gowda
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.
April 26, 2022

This works, thank you @Patrick 

kiranmai_genkolla January 19, 2024

Hi @Patrick ,

i have used this code in customfield on behaviour .. where pretext is populating but its not storing any data in that field

Patrick
Contributor
January 25, 2024

@kiranmai_genkolla 

hmm..it works for me with Jira 9.12  / latest Script Runner

Suggest an answer

Log in or Sign up to answer