Schema Object field returns additional Key ID attribute along with value.
Asked by Gurunathan Kanniappan:

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

![jira issue.png](/t5/image/serverpage/image-id/317556iDBE54143CF631148/image-size/large?v=v2&px=999 "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


Answers:
author: Peter-Dave Sheehan
body: 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.


author: Gikku
body: [@Gurunathan Kanniappan](/t5/user/viewprofilepage/user-id/5448465) Since Hostname is the label assigned, you can use {{issue.customfield_48401.label}}

comments: author: Gurunathan Kanniappan
body: Hi Gikku

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

![label details.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/317731i050C5C8AF815D62C/image-size/large?v=v2&px=999 "label details.jpg")


Tags: assets

jira

jira-service-management

jira-software-unknown-hosting-type

scriptrunner

unknown-hosting-type