jirascriptrunner-for-jira

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


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

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

I wrote the following code to extract the value of the custom field: 

enter image description here

  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? enter image description here

The type of the field is a database values selection field so this will not work

enter image description here  


Solution

  • Here is the solution:

     def customField =  ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10790");// here replace the ID with ID of your custom field.
                         def value = issue.getCustomFieldValue(customField) ;   
    
                        newissue.setCustomFieldValue(customField, value)