Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hey,
I'm trying to send form value (created with script field) and send the input to rest endpoint.
I'm sending the issue key and textarea input.
script field:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper
import com.atlassian.jira.sal.JiraApplicationProperties
import com.atlassian.jira.plugin.webfragment.model.JiraHelper def issueKey = issue.getKey()
'''
<form action="/rest/scriptrunner/latest/custom/comment" class="aui">
<fieldset>
<textarea class="textarea" name="comment" id="textarea-id" placeholder="Your comment here..."></textarea>
</fieldset>
<input type="hidden" name="issuekey" value="'''+issueKey+'''">
<div class="buttons">
<input class="button submit" type="submit" value="Submit" id="comment-save-button">
</div>
</form>
'''
The problem is that i'm trying to get those values with rest endpoint, but for some reason I can't get the issueKey..
Rest endpoint:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import groovy.transform.BaseScript
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.bc.issue.IssueService
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.json.JsonBuilder
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
def log = Logger.getLogger("com.test.Neta")
log.setLevel(Level.DEBUG)
@BaseScript CustomEndpointDelegate delegate
comment(httpMethod: "GET") { MultivaluedMap queryParams ->
def comment= queryParams.getFirst("comment")
def issuekey = queryParams.getFirst("issuekey") as Long
log.debug("------------------------------------comment---------------------------------: "+comment)
log.debug("-----------------------------------------------issuekey----------------------: "+issuekey)
}
I can see the params in the URL:
http://localhost:8080/rest/scriptrunner/latest/custom/comment?comment=gfdgdfg&issuekey=STAR-1
Error massage:
{"message":"For input string: \"STAR-1\"","stack-trace":"java.lang.NumberFormatException: For input string: \"STAR-1\"\r\n\tat Script710$_run_closure1.doCall(Script710.groovy:26)\r\n\tat com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:304)\r\n\tat com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.getUserEndpoint(UserCustomScriptEndpoint.groovy:195)\r\n","status-code":"INTERNAL_SERVER_ERROR"}
Thanks!
That is right. You have
def issuekey = queryParams.getFirst("issuekey") as Long
Your code tries to convert STAR-1 to long and fails
you should change your code to
def issuekey = queryParams.getFirst("issuekey")
def issueId = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issuekey)
Hey,
Thanks for your answer!
You were right, that was the problem.
I change the script to :
def issuekey = queryParams.getFirst("issuekey") as String
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register Now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.