Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,553,378
Community Members
 
Community Events
184
Community Groups

Scriptrunner - get checkbox values

Hi,

I'm trying to create a button on a story screen, that when the user clicks will ultimately read a checkbox (which has 3 possible values, 'Test', 'QA' and 'Prod'), and tick the next checkbox automatically (eg if "Test" is already checked off, it will check off "QA" for me).  The next iteration would then be to transition the story from the "Test" column to the "QA" column, but that is for another day.

I am however stuck at being able to read in the checkbox values.  I've tried all the code fragments I've found here, and none of them seemed to work correctly for me.

I've created the button, and linked it to the action "run code and display a flag".  A basic REST Endpoint runs and displayed the flag.  So far, all good.  When I went to add in some code to read the values and then display the values read in as part of the flag (just confirmation to me that everything is working), I get to the point where i try to read in the values, and nothing happens - the flag doesn't get displayed until I comment out the offending line of code.

Here is my code - the custom check box is called "Validation"

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

validate(httpMethod: "GET") { MultivaluedMap queryParams ->

// the details of getting and modifying the current issue are ommitted for brevity
// def issueId = queryParams.getFirst("issueId") as Long // use the issueId to retrieve this issue

def issueManager = ComponentAccessor.getIssueManager()
def issueId = queryParams.getFirst("issueId") as Long
def issue = issueManager.getIssueObject(issueId)
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Validation");
// def selectedValues = customField.getValue(issue)*.value


def flag = [
type : 'success',
title: "Issue validated",
close: 'auto',
body : "This issue has been validated : " //${selectedValues}"
]

Response.ok(JsonOutput.toJson(flag)).build()
}

As soon as I remove the comments from 

// def selectedValues = customField.getValue(issue)*.value

I get an error in the script window 

scriptrunner error.PNG

I'm not sure why I should be getting this error, it was the accepted solution on a question from this board a couple of years ago (https://community.atlassian.com/t5/Jira-Core-questions/How-to-get-checkbox-value-with-scriptrunner-in-post-function/qaq-p/278604) .  I'm running Jira 7.10.1 and Scriptrunner 5.4.12.  Is there any documentation that you can point in my direction so I can understand what I'm doing wrong?

I've tried reproducing the code from http://scriptrunner-docs.connect.adaptavist.com/jiracloud/script-console.html#_extracting_the_values_from_a_checkbox_custom_field

This comes up with a warning triangle saying "Failed type checking and we don't know why, it's our fault not yours @ line 1, column1 ." amongst other errors.

 

Adrian

 

 

1 answer

1 accepted

0 votes
Answer accepted

My script fragment was not passing in the Issue ID.  I was able to get my script working using the code fragment:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.sal.api.ApplicationProperties
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import groovy.json.JsonOutput

@BaseScript CustomEndpointDelegate delegate

def applicationProperties = ScriptRunnerImpl.getOsgiService(ApplicationProperties)
def issueManager = ComponentAccessor.getIssueManager()

validate(httpMethod: "GET") { MultivaluedMap queryParams ->

def issueId = queryParams.getFirst("issueId") as Long

if (!issueId)
return

def issue = issueManager.getIssueObject(issueId)

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Validation")
def value = issue.getCustomFieldValue(cf)

def flag = [
type : "success",
title: "Validation",
close: "auto",
body : "$value"
]

Response.ok(JsonOutput.toJson(flag)).build()
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events