Schema Object field returns additional Key ID attribute along with value.

Gurunathan Kanniappan April 10, 2024

We have 2 object types in our asset schema.  Servers and databases.  Showing the server attributes here.

jira issue.png

 

 

Then we have a custom field each called “Server(s)”  and “Database(s)  ( 48401 and 52500  respectively).    

When the asset object picker gets the selected object however,  it is returning the hostname/database name concatenated with the key and we’ve tried very way we can think of to reference only the “HOSTNAME”  attribute of the selected object.

 

Any idea what we are missing here?  We’ve tried:

  • "{{ issue.customfield_48401 }}",  <- gives both server and key
  • "{{ issue.customfield_48401.key }}",   <- gives just the key as expected
  • "{{ issue.customfield_48401.HOSTNAME }}",   <- returns null no matter the case we use
  • "{{ issue.customfield_48401.value }}",   <- returns null
  • "{{ issue.customfield_48401.name }}",   <- returns null

 

Example:

"customfield_48402": [
      "CDSD0003_DG-caddld-499.belldev.dev.bce.ca (CNPI-3028740)"
    ],
    "customfield_46100": null,
    "customfield_48400": null,
    "customfield_48401": [
      "caddld-499.belldev.dev.bce.ca (CNPI-3029656)"
    ],

I wish to ignore  CNPI-3028740) and (CNPI-3029656)

Regards

Guru

2 answers

1 vote
Peter-Dave 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.
April 26, 2024

Possibly, the reason is that your Asset field can contain more than one object. And even when a single one is selected, the expression still returns a list. I have no experience with automation expressions to advise you on how to get a single value from a list.

But you could try with a native scriptrunner script. Either as a workflow postfunction, a script listener or (I have less experience with that) an automation to execute a groovy script:

 

import groovy.json.JsonBuilder
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient

def apiBaseUrl = 'https://bitcap-uat-wyn-ctrl-bitcap.apps.ocp-uat-wyn.bell.corp.bce.ca'
def apiPath = '/api/v2/job_template/207/launch/'

//issue should be supplied by the script context
def server = issue.getCustomFieldValue('Server(s)')
def db = issue.getCustomFieldValue('Database(s)')

if (server instanceof List) {
server = server[0]
}
if (db instanceof List) {
db = db[0]
}

def body = [
extra_vars: [
server : server.label,
due_time : '2024-03-21 11:31:27',
request_id : issue.key,
requested_item_id: issue.key,
sys_id : issue.id.toString(),
os : 'Other',
type : db.label
]
]
log.info new JsonBuilder(body).toPrettyString()

def restClient = new RESTClient(apiBaseUrl)
restClient.headers = [header1: 'valueofheader1', header2: 'valueorheader2']

restClient.post(path: apiPath, contentTYpe: ContentType.JSON, body: body)

This is fairly basic. You can add additional error/response handling.

0 votes
Gikku
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2024

@Gurunathan Kanniappan Since Hostname is the label assigned, you can use {{issue.customfield_48401.label}}

Gurunathan Kanniappan April 11, 2024

Hi Gikku

{{issue.customfield_48401.label}} returns a null value.

label details.jpg

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events