Forums

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

Add the name of the organization to the custom field[ScriptRunner]

arno
Contributor
December 22, 2023

Hi all

I wanted to automatically add the organization name to the custom field, but I found that I couldn't get the specified name. Here's my code


import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager
def customer = customFieldManager.getCustomFieldObject('customfield_11029')
def org = customFieldManager.getCustomFieldObject('customfield_12012')
def value = issue.getCustomFieldValue(org)
log.error(value)
def a = value.toString()
log.error(a)
issue.setCustomFieldValue(customer,value)
info.png
I try use "def b = a.name ",But there is an error, how can I improve my code

1 answer

0 votes
PD Sheehan
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.
December 22, 2023

The Organization field will store a list of CustomerOrganization objects.

You can combine the list (even if you only expect 1) as comma-separated string.

Here is your script, slightly modified:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager
def customerCf = customFieldManager.getCustomFieldObject('customfield_11029')
def orgCf = customFieldManager.getCustomFieldObject('customfield_12012')

def orgValues = issue.getCustomFieldValue(orgCf) as List

if(!orgValues) return null //exist the script if the org field is empty

//Organization store a list. Even if in most case you only have one. We can join them with comma (and a space for human readability)
issue.setCustomFieldValue( customerCf, orgValues.collect{it.name}.join(', '))
arno
Contributor
December 25, 2023

Hi @PD Sheehan 

 Thank you for your reply

 I tried it as you suggested and met with a mistake: 

No such property: name for class: java.lang.Object

it seems I'm not allowed to use "{it.name}"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events