Hi ,
I am trying to add a Custom Web Item, i have added the button , but comment is not adding but flag is showing. How can i add Comment using REST Endpoint of Script Runner.
Please suggest.
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
approve(httpMethod: "GET") { MultivaluedMap queryParams ->
// the details of getting and modifying the current issue are ommitted for brevity
def issueId = queryParams.getFirst("issueId") as String // use the issueId to retrieve this issue
def flag = [
type : 'success',
title: "Issue approved",
close: 'auto',
body : "This issue "+issueId+" has been approved for release"
]
Response.ok(JsonOutput.toJson(flag)).build()
}
In the script, you can add something like this:
import com.atlassian.jira.component.ComponentAccessor
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(issueId)
String reporter = issue.getReporter().getUsername()
commentManager.create(issue,user,"Hi [~reporter], This issue "+issueId+" has been approved for release",true)
I hope this helps.
@John Chin thanks a lot mate for your help!
I have tried to add below script but it's not working, not adding comment..when clicking on script fragment button.
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
approve(httpMethod: "GET") { MultivaluedMap queryParams ->
def issueId = queryParams.getFirst("issueId") as String
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(issueId)
String reporter = issue.getReporter().getUsername()
commentManager.create(issue,user,"Hi [~reporter], This issue "+issueId+" has been approved for release",true)
def flag = [
type : 'success',
title: "Issue approved",
close: 'auto',
body : "This issue "+issueId+" has been approved for release"
]
Response.ok(JsonOutput.toJson(flag)).build()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vikrant,
Do you see any errors in the JIRA log (via $JIRAHOME/log/application-jira.log) ?
If you debug the script, do you received the issueId information?
For example, add the debug log in your script:
def issueId = queryParams.getFirst("issueId") as String
log.warn "issueId:" + issueId
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.