Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

issue.getCustomFieldValue() returns null when trying to get value of a read-only field

Yen-Wu Lo September 13, 2020

I'm running Scriptrunner with Jira Service Desk to create a application portal for a system called "PBS".

In my portal, I want to make a read-only select field called "System", and set the default value to "PBS" so I could use this field later in a database-picker.

However, when I try to get the value of this read-only field with the following code:

issue.getCustomFieldValue(ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("System"))

It always return null. If I comment out the line which makes the "System" field read-only, it works normally.

Could anyone please tell me if this is by design or a bug?

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Yen-Wu Lo September 24, 2020

This is solved in ScriptRunner 6.10.0. I believe this is a bug related to https://productsupport.adaptavist.com/browse/SRJIRA-4611.

0 votes
Marc Minten _EVS_
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.
September 14, 2020

Do not know what you mean with "... make a read-only select field called "System" ..." and "... the line which makes the "System" field read-only ..." . can you add these lines ?

Yen-Wu Lo September 14, 2020

Thank you for your reply. By "making the "System" field read-only" I mean:

getFieldByName("System").setHidden(true)

 So the user can see the field and its default value, but cannot edit it.

 

Edit: Sorry, wrong code above. I meant:

getFieldByName("System").setReadOnly(true)

 

Marc Minten _EVS_
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.
September 14, 2020

Ok. It seems you are scripting a behavior ? Please give more context when you describe a "problem" !

Are you creating the issue ? Then the custom field does not contain the value yet, it is still only in the form field on the screen... In that case it is "logic" that your line returns null.

Please provide a bigger part of your script and context. with some parts of lines it it hard to understand what you are doing...

Yen-Wu Lo September 14, 2020

Thanks again,

Yes, I'm scripting a behaviour for a field in the issue creation screen.

I don't know if what you described is true, because I'm able to get the value of the field with the exactly same code when the field is not read-only. The code only returns null when the field is read-only.

Marc Minten _EVS_
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.
September 14, 2020

Aha!

Again, it really depends how you have written your code, so as long as you do not (want to) share more details, it is hard to guess.

In "normal" cases, when you create (or edit) an issue, the fields you modify are not yet saved to the issue, you find the values only n the form fields (thats why there is a method to get the value from the form field).

Only after saving it to the issue, you can count to find the values in the issue (getCustomFieldValue); But again, you can of course "fiddle" in your code and write yourself to the issue ...

Marc Minten _EVS_
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.
September 16, 2020

Status of your issue ?

Resolved ?

Yen-Wu Lo September 20, 2020

Hi,

I do not believe this is the case, because like I said, I can get values from non-custom fields before I submit the form. I should be able to get them from custom fields as well.

Perhaps what you described is how SR works in Jira, but not Jira Service Desk.

TAGS
AUG Leaders

Atlassian Community Events