It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Setting default value for a custom text field

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

0 votes
Answer accepted

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

Ah, thank you! :)

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you