ScriptRunner script field to rest endpoint JIRA Edited


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.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">
<textarea class="textarea" name="comment" id="textarea-id" placeholder="Your comment here..."></textarea>
<input type="hidden" name="issuekey" value="'''+issueKey+'''">
<div class="buttons">
<input class="button submit" type="submit" value="Submit" id="comment-save-button">

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.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

def log = Logger.getLogger("com.test.Neta")

@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:


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\r\n\tat\r\n","status-code":"INTERNAL_SERVER_ERROR"}



1 answer

1 accepted

0 vote
Alexey Matveev Community Champion Dec 20, 2017

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)


Thanks for your answer!

You were right, that was the problem.

I change the script to :

def issuekey = queryParams.getFirst("issuekey") as String


Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published 2 hours ago in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

17 views 0 1
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you