Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

how to update a customfield value by running http request in post function?

rakesh rocckz September 19, 2019

I have a multiline text field. is it possible to run a post function with HTTP request and get the JSON response and show in the text field when I click on create an issue?is it possible to set the field value with the POST function by running an HTTP GET request behind the scenes and getting the response and parse it and update field value with JSON response?????please share a snippet it would be very helpful

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 20, 2019

Let me see if I understand correctly.

You want to create a new issue in jira. When you click the create button to submit the issue creation form, you would like to run a custom post-function script that will execute an HTTP GET request to some third party tool (perhaps using some attributes entered in the issue creation form as part of the request), then update the multiline custom field with the JSON response from the HTTP GET request.

import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import groovy.json.JsonOutput

def customFieldId = 123456 //the ID of your multiline text field

def httpBuilder = new HTTPBuilder('http://example.com')
httpBuilder.request(Method.GET, ContentType.JSON) {
headers."your custom header" = "custom header value"
uri.path = '/path/to/endpoint'
uri.query = [mapOf: "keyvaluepairs"]
response.success = { resp, data ->
issueInputParameters.addCustomFieldValue(customFieldId,JsonOutput.toJson(data))
}
response.failure = {resp, data ->
//do something with the failed response
}
}

Suggest an answer

Log in or Sign up to answer