You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I'm aware that this is potentially achievable using asset custom fields and reference asset custom fields, however I have a unique circumstance that extends beyond this.
Context:
I have an asset model that has four object types:
I have exposed all these object types through custom fields like so:
Using ScriptRunner, I want to define a field behaviour whereby options for customfield D (which is object type D) only displays objects D1, D2 and D3 if B1 in customfield B has been selected. Otherwise, I only want D1 and D2 to be selectable. Any assistance with the groovy aspect of this would be much appreciated. I've been able to interact with assets previously using the ObjectFacade, however setting the field options is proving to be slightly more challenging.
Hi @Amos
It's a bit of a tricky requirement. You won't be able to filter the Asset field using the Behaviour. This must be done using the Field's configuration and adding the IQL query.
However, for the Behaviour, you must create 2 separate Server-Side Behaviours, i.e. for both the Asset fields separately and with that you will need to use the setErrorMessage to trigger the error when a wrong option is selected.
Below are two sample codes for your reference: (it's not 100% tested)
import com.adaptavist.hapi.jira.assets.Assets
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def asset = getFieldById(fieldChanged)
def assetValue = asset.value.toString()
def subAsset = getFieldByName('Sub Asset')
def subAssetValue = subAsset.value.toString()
subAsset.clearError()
if (assetValue in ['SA-1', 'SA-8']) {
def filter = Assets.search(""""Host" IN (${assetValue})""" ).collect() as List<ObjectBean>
def filterNames = filter.objectKey as List<String>
if (subAssetValue.length() > 0) {
if (subAssetValue.contains(',')) {
def subAssetFilter = subAssetValue.replace('[','').replace(']','').trim().split(',') as List
if (!filterNames.intersect(subAssetFilter)) {
subAsset.setError('Invalid Sub-Asset Selected')
}
} else {
if (!filterNames.contains(subAssetValue)) {
subAsset.setError('Invalid Sub-Asset Selected')
}
}
}
}
and
import com.adaptavist.hapi.jira.assets.Assets
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def asset = getFieldByName('Assets')
def assetValue = asset.value
def subAsset = getFieldById(fieldChanged)
def subAssetValue = subAsset.value.toString()
subAsset.clearError()
if (assetValue in ['SA-1', 'SA-8']) {
def filter = Assets.search(""""Host" IN (${assetValue})""" ).collect() as List<ObjectBean>
def filterNames = filter.objectKey as List<String>
if (subAssetValue.length() > 0) {
if (subAssetValue.contains(',')) {
def subAssetFilter = subAssetValue.replace('[','').replace(']','').trim().split(',') as List
if (!filterNames.intersect(subAssetFilter)) {
subAsset.setError('Invalid Sub-Asset Selected')
}
} else {
if (!filterNames.contains(subAssetValue)) {
subAsset.setError('Invalid Sub-Asset Selected')
}
}
}
}
The first one is for Custom Field B and the second is for Custom Field D.
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
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.
Due to the dynamic nature that the Asset Custome field load the available options, Behaviours is not going to be able to interfere.
The only thing you can do with Behaviours is to intercept the user's selection, place the form in an error state, and provide feedback to the user that the selection is invalid. You can't limit the selection itself.
But that should be possible within the Issue Scope IQL in the custom field configuration.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Peter, we've been trying to use the Filter Issue Scope (AQL) to do this, but with very limited success. I created an outbound reference between the objects I wanted the behaviour to occur with. I then tried:
object HAVING outboundReferences(Label IN (${customfield_xxxxx}))
There error we get is <iql,Placeholder not support in current context> but this is not a very useful error message, so we're not having much luck on this front. It seems like the simple and obvious answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My take on this, having just done a few hours of looking around is Filter Issue Scope (AQL) doesn't support custom fields that are asset or reference asset object fields. If it does, then the documentation leaves a lot left to be desired.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not at all, I have several Asset Custom fields with complex cascading dependencies. Enough to give you a headache trying to understand what it does:
(Customer IN (${Customer(s)${0}}) OR object having outR(objectType = Customer AND object having inR(objectType = "Customer" and Key IN (${Customer(s)${0}}),referenceType in ("Has")))) AND "Issue Types" like ${issuetype.name} AND "Environment Type" IN (${Environment Type${0}})
In my example "Customer(s)" and "Environment Type" are both Asset fields.
It's a bit difficult to consult in the abstract, if you could attach some concrete examples with screenshots, I'm sure I can help you come up with an Issue Scope IQL
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.