How to get populate summary field with custom field value Select List (cascading) with only text

Zdeněk
Contributor
August 4, 2022

Hello

I have copied and adjusted a code from here. I just have one issue with that. I want to populate summary field based on Select List (cascading). When I run sucessfully this code, it returns the value in this format: Objednávka [null:Audit staff, 1:Travel Tickets]. Is it possible to get rid of the null, parenthesis and the number? I just need the text from the field. I spend like 4 hours looking for the solution but nothing worked for me. 

Could you please take a look at my code? 

 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def myCustomField1 = customFieldManager.getCustomFieldObjectByName('Typ objednávky a předmětu')

def value1 = issue.getCustomFieldValue(myCustomField1).toString()

def concatValue = "Objednávka" + " " + value1

issue.setSummary(concatValue)

1 answer

1 accepted

0 votes
Answer accepted
Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 5, 2022

Hi,

when you get the value from a cascading field Jira will return a Hashmap you can confirm it like that

def value1 = issue.getCustomFieldValue(myCustomField1)

log.warn(value1.getClass())//will return ==> class java.util.HashMap

Then we just need to know how to access to the value inside the hashmap, you will need to know the key (i assume Jira will not change the key everytime i want to access it)

so i just need to log the value i get like that

log.warn(value1)//return [null:Test, 1:test]

Then to access my first value i can do this

def firstValue = value1.get(null)
def secondValue = value.get("1")// the key are string
Zdeněk
Contributor
August 23, 2022

Hello Mohamed. 

Thank you for your advice. I was not able to make it running but I got help from someone else. We made it running with ScriptRunner Behaviours. 

The code for the solution: 

 

def LOV = getFieldByName("Typ objednávky a předmětu")
def sum = getFieldById("summary").setReadOnly(true)
def selectedOption = LOV.getValue() as String
def result = selectedOption.minus("[").minus("]")

sum.setFormValue("Žádost o nákup: ${result}")
Maybe it will help somebody. 

Suggest an answer

Log in or Sign up to answer