We have 2 object types in our asset schema. Servers and databases. Showing the server attributes here.
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:
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
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.
@Gurunathan Kanniappan Since Hostname is the label assigned, you can use {{issue.customfield_48401.label}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gikku
{{issue.customfield_48401.label}} returns a null value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.