Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events