Scriptrunner - Custom Built-in Script - How to get the value of a field

Tobias Meyer May 10, 2021

Hi All

I'm writing a custom Built-in Script with Scriptrunner (/plugins/servlet/scriptrunner/admin/builtin). I have two select list fields to select different values. The first select list field is quite simple. I can run a "query" to get all the values I want. The second list field should only contain values based on the first field. The problem is: How do I get the value from the fist field to use to filter in the second field. 

Built-in Scripts 2021-05-11 08-02-03.png

How do I get the value of the first select list (in the example above DUMMY) to filter the values on the second select list field? 

 

My code so far:

package com.onresolve.scriptrunner.canned.jira.admin

import com.onresolve.scriptrunner.canned.CannedScript
import com.onresolve.scriptrunner.canned.util.BuiltinScriptErrors
import com.onresolve.scriptrunner.canned.util.SimpleBuiltinScriptErrors
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import org.apache.log4j.Level
import org.apache.log4j.Logger

class GetGroupsExample implements CannedScript {

Logger LOG = Logger.getLogger("GetGroups")


@WithPlugin("com.riadalabs.jira.plugins.insight")
@PluginModule IQLFacade iqlFacade

public static String FIELD_GRUNDGERUEST_FIELD = "FIELD_GRUNDGERUEST_FIELD"
public static String FIELD_FIRMA_FIELD = "FIELD_FIRMA_FIELD"


@Override
List getCategories() {
return ["SYSTEM"]
}

@Override
List getParameters(Map params) {
[
[
Label : "First Select List",
Name : FIELD_FIRMA_FIELD,
Description: """Select a value""",
Type : "list",
Values : getFirma()
],
[
Label : "Second Select List",
Name : FIELD_GRUNDGERUEST_FIELD,
Description: """Select a value""",
Type : "list",
Values : getFields("Grundgerüst")
]

]
}

Map getFields(String field) {
Map<Long, String> fields = [:] as Map<Integer, String>

List<ObjectBean> objects = iqlFacade.findObjects(21, "objectType in objectTypeAndChildren(\"Rechte und Rollen\") and objectType = \"${field}\"")

for (ObjectBean object : objects) {
fields.put(object.getId(), object.getLabel())
}

return fields
}

Map getFirma() {
Map<Long, String> fields = [:] as Map<Integer, String>

List<ObjectBean> objects = iqlFacade.findObjects(21, "objectType in objectTypeAndChildren(\"Firma\") and objectTypeId != 3709")

for (ObjectBean object : objects) {
fields.put(object.getId(), object.getLabel())
}

return fields
}

@Override
BuiltinScriptErrors doValidate(Map<String, String> map, boolean b) {
SimpleBuiltinScriptErrors errorCollection = new SimpleBuiltinScriptErrors()
[FIELD_GRUNDGERUEST_FIELD, FIELD_FIRMA_FIELD].each {String p ->
if (! map[p]) {
errorCollection.addError(p, "Please provide ID")
}
}
if (errorCollection.hasAnyErrors()) return errorCollection
errorCollection
}

@Override
Map doScript(Map<String, Object> map) {
return null
}

@Override
String getDescription(Map<String, String> map, boolean b) {
return null
}

@Override
Boolean isFinalParamsPage(Map map) {
return true
}

@Override
String getName() {
return "[kreuzwerker] Get Groups"
}

@Override
String getDescription() {
return "Select Groups"
}
}

 

The method call getFields("Grundgerüst") should contain not a hard coded string but the value of the first select list. 

 

Many thanks in advance

Tobias

0 answers

Suggest an answer

Log in or Sign up to answer