Scriptrunner Behavior Issue Type formvalue type

Pedro Felgueiras
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.
May 22, 2023

I found out about this weird behavior and I'm checking if this is right. 

I have the following code on the initializer of the behavior 

 

def issueType = getFieldById("issuetype")

issueType.setDescription("${issueType.formValue.class}")

 

If I'm on the edit screen I got a String, if I'm on the create screen I got a Long. 

 

is this the expected behavior?

2 answers

1 accepted

0 votes
Answer accepted
Radek Dostál
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.
May 22, 2023

When you're on Create, the issuetype "getter" won't work, it's not a regular field, per se, don't know the exact magic or logic, but..

getIssueContext().getIssueType() // to get IssueType object
getIssueContext().getIssueTypeId() // get the ID (as String, mind you)
getIssueContext().getIssueType().getName() // the pretty name

You can use these in either create or edit, and they should return reliable and consistent values. Not sure what FormField#getFormValue() returns outside of IssueContext, but the above is the way to get reliable stuff out of it.

0 votes
Graham Twine
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.
May 22, 2023

Hello @Pedro Felgueiras 

 

As Radek has mentioned, it is better to use the issueContext as per the Adaptavast behavior documentation, something to consider. On the create screen the issue does not exist in the database yet.

Suggest an answer

Log in or Sign up to answer