Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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
Community showcase
Asked in Jira Service Management

JSM June ask me anything (AMA)

Hello Community members! We’re wrapping up the end of JSM June with an Ask Me Anything (AMA) with the Jira Service Management product team. This is your chance to ask all your ITSM questions to o...

262 views 13 14
View question

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you