Hello community,
I have 2 objectTypes "Application" and "Server" in my Insight Schema.
"Application" object has attribute of type "object" called "Application hosts", referencing "Server" objects.
I have also created 2 Insight customfields "CMDB - Server" and "CMDB - Application" linked to these 2 objectTypes and I display them in an "create issue" screen.
I would like to code a behaviour script that displays the "Application hosts" attribute values in the "CMDB - Servers" customfield when an application is selected in the "CMDB - Application" customfield.
Exemple :
object "Application X" has 2 values in attribute "Application hosts" : "Server A" and "Server B".
Then, in the "create issue" screen, when I select "Application X" in the "CMDB - Application" customfield, I would like to have the objects "Server A" and "Server B" automatically selected in the "CMDB - Server" customfield.
Thanks a lot for your help,
Aimane
You don't need behaviours for this.
This is possible out of the box with Insight Custom field configuration.
Try configuring your "CMDB - Server" as such:
Now, just leave your CMDB - Server field off the screen and when you create an issue, server objects will be added to the field automatically.
If you absolutely need for the field to be visible and editable during creation, then yes, a behaviour script will be needed.
Create a behaviour with appropriate mapping and add the CMDB Application field.
Create a server-side script and start with a script that looks somewhat like this:
if(underlyingIssue){
//don't do anything if the issue exists (this means we're currently editing an issue)
return
}
def applicationField = getFieldById(fieldChanged)
def serverField = getFieldByName('CMDB - Server')
def selectedApplications = applicationField.value
if(!applicationField.value){
//no value in Application field, remove server values and exist
serverField.setFormValue(null)
return
}
if(selectedApplications instanceof String){
selectedApplications = [selectedApplications]
}
def iqlServer = "objectType = Server and inR(objectType = Application and Key in (${selectedApplications.join(',')}"
def serverObjects = Assets.search(iqlServer)
serverField.setFormValue(serverObjects*.objectKey)
Thanks a lot for taking time and for this very complete answer but still does not fully resolves my problem.
I admit that I did not fully describe my use case ... :(
In fact, I have actually 2 attributes in object "Application" .
And both of them are referencing "Server" objects. (same objectType) ...
I have then 2 Insight custom fields "CMDB - Application Server" and "CMDB - Database Server" that I want to fill in the creation screen (they must be visible and editable yes -> So, I need a behaviour).
That's why IQL does not work for my usecase. I really need like a script that copies the attribute values in the corresponding insight customfield.
Any idea ?
Thanks a lot !
Aimane
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That is when the Reference Type in your attribute configuration comes in handy.
The two attributes that point to Server should have different Reference Types.
Then in the IQL (either type of solution), you can add a second argument to the inboundReference() function (abbreviated to inR() in my earlier response) in the IQL.
E.g.
object having inR(objectType=Application and Key in (${CMDB - Application${0}}), refType in ("Name of unique Reference Type"))
You can read more about this in https://confluence.atlassian.com/display/SERVICEDESKSERVER/Advanced+searching%3A+AQL+-+Assets+Query+Language (search for referenceType and inboundReferences
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much @Peter-Dave Sheehan !!!
refType in() was exactly what I was looking for !
Everything is working well now.
Thanks again.
Aimane
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aimane SBAI ,
ScriptRunner behaviours on Server/DC support Asset custom fields, so you should be able to get the value of the "CMDB - Application", and set the values of the "CMDB - Server" in the same way you would normal fields.
If you are on version 7.11 or above of ScriptRunner, you are able to use the HAPI Assets/Insight module to easily access the information of the Asset you have selected in the "CMDB-Server" field. You can find the documentation of how to do this here: https://docs.adaptavist.com/sr4js/latest/hapi/work-with-assets-insight
Does this help?
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.