Hello all,
we are currently populating an external system with the Jira ID via a put call. We need this to be able to send updates from this system to the respective Jira issue.
Thus, when creating the issue via workflow, we want to trigger a script runner script which will then perform the put post. However, we are currently still getting an error message, the body is intentionally empty for now for testing purposes. The endpoint differs to a field value which is filled by the creation, this is happening via post call from this external system.
I suspect the syntax of my script does not fit.
package utils
import groovy.json.JsonOutput
import groovyx.net.http.ContentType
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
public class FreshservicePost{
public static String postResponse(Issue issue)
{
def hostUrl = "https://markant-fs-test.freshservice.com/"
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_12727")
def strErgebnis = issue.getCustomFieldValue(customField).toString()
def endpointAndQuery = "https://markant-fs-test.freshservice.com/itil/changes/" +strErgebnis+".json"
// Turn the data will be sent into JSON, the HTTP requests specify in the header to accept application/JSON
// If the API accepts different types then you can change this and format the data accordingly
def bodyJson = JsonOutput.toJson([data: "{
"itil_change": {
"custom_field_attributes": {
"external_jira_id_404134": "123"
}
}
}"])
//def put(def hostUrl, def endpointAndQuery, def bodyJson) {
def client = new RESTClient(hostUrl)
client.setHeaders([
'Accept' : ContentType.JSON,
// If authentication mechanism of the API is Basic Authentication, 'Authorization' header with username and password encoded as Base 64 can be specified here
'Authorization': "Basic ${'gPClHSQlxwCDf08NXTC:x'.bytes.encodeBase64()}"
])
client.handler.success = { HttpResponseDecorator response, json ->
json
}
client.handler.failure = { HttpResponseDecorator response ->
// Failure can be handled here
log.error response.entity.content.text
[:]
}
client.put(
path: endpointAndQuery,
contentType: ContentType.JSON,
body: bodyJson
)
//}
}
}
Here is the error:
2021-12-02 09:51:19,519 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue CMTM-6567 for user 'tspraul'. View here: https://www.mnet.markant.de/jiraTest/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=Markant+CMTM+Workflow+v1.1&descriptorTab=postfunctions&workflowTransition=191&highlight=6
groovy.lang.MissingMethodException: No signature of method: utils.FreshservicePost.main() is applicable for argument types: ([Ljava.lang.String;) values: [[]]
Possible solutions: wait(), wait(long), find(), any(), wait(long, int), any(groovy.lang.Closure)
at com.onresolve.scriptrunner.runner.RunScriptInvoker$run.call(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptWithRawBindings(AbstractScriptRunner.groovy:196)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScript(AbstractScriptRunner.groovy:190)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScript$11.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:216)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$9.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:301)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$2.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScript(AbstractScriptRunner.groovy:311)
at com.onresolve.scriptrunner.runner.ScriptRunner$runScript$12.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.utils.TypedCustomScriptDelegate.execute(TypedCustomScriptDelegate.groovy:19)
at com.onresolve.scriptrunner.canned.jira.utils.TypedCustomScriptDelegate$execute$0.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction.execute(CustomScriptFunction.groovy:53)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction$execute.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.workflow.AbstractWorkflowCannedScript.execute(AbstractWorkflowCannedScript.groovy:23)
at com.onresolve.scriptrunner.canned.jira.workflow.AbstractWorkflowCannedScript$execute.call(Unknown Source)
at com.onresolve.scriptrunner.jira.workflow.AbstractScriptWorkflowFunction$_run_closure2.doCall(AbstractScriptWorkflowFunction.groovy:89)
at com.onresolve.scriptrunner.jira.workflow.AbstractScriptWorkflowFunction$_run_closure2.doCall(AbstractScriptWorkflowFunction.groovy)
at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy:370)
at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy)
at com.onresolve.scriptrunner.runner.ScriptExecutionRecorder.withRecording(ScriptExecutionRecorder.groovy:13)
at com.onresolve.scriptrunner.runner.ScriptExecutionRecorder$withRecording.call(Unknown Source)
at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl.execute(DiagnosticsManagerImpl.groovy:368)
at com.onresolve.scriptrunner.runner.diag.DiagnosticsExecutionHandler$execute$3.call(Unknown Source)
at com.onresolve.scriptrunner.jira.workflow.AbstractScriptWorkflowFunction.run(AbstractScriptWorkflowFunction.groovy:82)
Hopefully, somebody can help me!
Thank you in advance,
Best regards!
Hi!
I suppose you are doing this in a workflow postfunction or in an automation rule?
If so, try putting everything that is in the postResponse function in the script. The Issue context is already provided.
So your code would be:
import groovy.json.JsonOutput
import groovyx.net.http.ContentType
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
<code of the postResponse method here>
Let me know if this helps,
Jeroen
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.