Forums

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

code for retrieving the value of a custom field is not working

Mouna Hammoudi
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 22, 2023

I am trying to retrieve the value of a custom field, the custom field looks like this in my Jira issue: 

Capture1.PNG

I have been able to find the ID by rightclicking on the custom field and choosing the option Inspect Element, Here is the ID: 

Capture.PNGI wrote the following code to extract the value of the custom field: 

 

  def customField =  ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10790");// here replace the ID with ID of your custom field.

  def value = (String)issue.getCustomFieldValue(customField);

                   
log.warn("MOUNA CAMELIA VALUE "+value )

The problem is that I am getting the following value in my log: 

 MOUNA CAMELIA VALUE 1000547

This is a wrong value since it should normally return the value shown below. How to fix this problem?

Capture1.PNG

 

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 22, 2023

Hi @Mouna Hammoudi

After reviewing your description, I have a doubt to clarify i.e. what type of custom field are you using for the Invest / Area Theme field?

From the look of the log output you have displayed, I suspect it is a DB Picker you are using. If this is so, then the output returned is correct. The DB Picker will return the id value that has been set in the DB Picker's SQL Configuration. 

If you want to get the value instead of the ID, you can refer to this working example from the Adaptavist Library.

I am looking forward to your feedback and clarification.

Thank you and Kind regards,

Ram

Mouna Hammoudi
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 22, 2023

Capture1.PNG

The type of the field is a database values selection field. Should the code here example from the Adaptavist Library work?

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 22, 2023

Hi @Mouna Hammoudi

From the screenshot you have shared, this doesn't appear to be the DB Picker field from ScriptRunner. 

Instead, it looks like it's from another third-party plugin.

To proceed, could you please share a screenshot of the field's configuration, i.e. something like:-

db_picker.png

I am requesting this so I can get a better understanding of the field you are using.

If the field is from another third-party plugin, please specify the Vendor the the plugin name.

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Mouna Hammoudi
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 25, 2023

@Ram Kumar Aravindakshan _Adaptavist_ 

Here is a screenshot of the custom field configuration "Invest. Area/Theme"

Capture1.PNG

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 25, 2023

Hi @Mouna Hammoudi

I can confirm that the field you are using is not from ScriptRunner. Instead, it is from another third-party plugin called Database Values for Jira.

Jira no longer supports this plugin as it is only compatible with Server instances and not even DC.

I suggest you change the approach you are currently using, i.e. do not use the Database Value for Java's Database Values Searcher field. 

Instead, use ScriptRunner's Database Picker or convert a Single Line Text Field into a Single Select or Multi Select field, depending on your requirement.

Thank you and Kind regards,

Ram

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
October 25, 2023

Hi @Mouna Hammoudi

Have you tried the suggestion I provided and changed the field to Database Picker to convert the Single Line Text Field to a Single or Multi Select List?

If yes, does it solve your issue?

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer