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
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
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()
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.