Hello I have a quite complex problem it seems:
I have 2 Asset object customfields configured "Service Category" and "Service". Both filter for their corresponding objectType to adjust the options that users can chose from in general. A "Service" object uses an attribute reference to a dedicated "Service Category" object. See following Screenshot:
I also know I can confgure an AQL Filter Issue Scope in my "Service" customfield like: "Service Category" = ${customfield_18702} to limit the "Service" options based on the value that has been chosen in the "Service Category" field before. This does not work, when the "Service Category" field is Empty.
Since I want to provide users the opportunity to either go and select the "Service Category" first and then get a prefiltered list with all linked "Services" according to the selection I also want to provide the opportunity to go the other way around. So that users chose a "Service" first out of all "Service" objects without AQL Issue filter scope. Can anyone help me out on that? Following tries did not work out and maybe I dont even need behaviours or I can use some workaround:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.customfields.option.Option
@WithPlugin("com.riadalabs.jira.plugins.insight")
@PluginModule ObjectFacade objectFacade
@WithPlugin("com.riadalabs.jira.plugins.insight")
@PluginModule IQLFacade iqlFacade
//Get the asset object field
def assetField = getFieldByName("Service")
log.warn("Asset Field: $assetField")
//Filter for specific Assets
def filter = 'objectType = "Service" AND \"Service Category\" = "SAP"';
//Run the AQL query using IQLFacade
def queryResult = iqlFacade.findObjects(filter, 0, 50)
//Verify if Asset objects are found
if (!queryResult) {
log.warn("No objects found for Filter: $filter")
return
}
/* ######################VERSION 1############################
//Extract ObjectBeans from result
def objectBeans = queryResult.objectBeanFilterResult.objectBeans
//ObjectBeans to options
def options = objectBeans.collect { ObjectBean objectBean ->
return [
id : objectBean.id,
value: objectBean.objectKey
]
}
//Options
log.warn("Options: $options")
//Set the options
assetField.setFieldOptions(options)*/
/* ######################VERSION 2############################
//Collect Asset keys
def objectBeans = queryResult.objects
def objectKeys = objectBeans.collect { it.objectKey }
log.warn("Object Keys: $objectKeys")
//Set the Asset Object Keys
assetField.setFieldOptions(objectKeys)*/
/* ######################VERSION 3############################
//Collect the object IDs
def objectBeans = queryResult.objects
def objectIds = objectBeans.collect { it.id as Long }
log.warn("Object IDs: ${objectIds}")
//Set the Asset Object Keys
assetField.setFormValue(objectIds)*/
Hi @Christoph
Were you able to find an answer to your question?
Thank you and Kind regards,
Ram
Hi Ram,
I remember that this is not possible since Filtering on Assets in specific Asset object customfields to adjust the shown options like a normal Jira Option/select list field works different.
For normal Jira select list fields this would work but for Assets not. I cannot tell you why exactly but if I remember correctly I also reached out to the Scriptrunner support and we could not find a solution.
I went with 3 fields now instead of just 2. The third field "Search Service" is a helper field which filters all Services and based on a selection the user makes "Service Category" and "Service" get prefilled.
"Service" then uses simple AQL filtering on the "Service Categoy" field like mentioned already. See my Screenshots:
1. Select a Service out of all possible objects.
2. Then the behaviour copies the selection into the correct "Service Category" and "Service" fields.
3. When updating the selection in "Search Service" gets removed and can be used as a dummy search field the next time a user opens Edit screen.
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.