Hi everybody!
I have a code that, when the status changes, transmits field values in Json format to another service, the code works fine, but there is a problem with passing an array of field values, now all values are transmitted as a string. How can I pass the values of a multiple choice field in the format ["1param", "2param", "3param"] ?
I will be grateful for any help
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import groovyx.net.http.HttpResponseException
import groovyx.net.http.HttpResponseDecorator
import java.util.Base64
import java.util.Base64.Encoder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import helper.RestHelper
import groovyx.net.http.ContentType
import groovy.json.JsonBuilder
import javax.ws.rs.core.Response
def client = new RESTClient(url)
//Change to match your username/password
def authBasic = Base64.getEncoder().encodeToString(("login"+":"+"pass").getBytes());
IssueManager im = ComponentAccessor.getIssueManager()
Issue currentIssue = im.getIssueObject(event.getIssue().getKey())
ChangeHistoryManager chm = ComponentAccessor.getChangeHistoryManager()
def lastChange = chm.getChangeHistories(currentIssue)[-1].getChangeItems()
log.warn(lastChange.field[1])
if ((lastChange.field[0].equals("status")) || (lastChange.field[1].equals("status"))) {
log.warn("status")
String oldStatus = lastChange.oldstring[0]
String newStatus = lastChange.newstring[0]
if (!newStatus.equals(oldStatus)) {
log.warn("test")
log.warn(currentIssue.getCustomFieldValue(16308))
log.warn(currentIssue.getCustomFieldValue(19700))
log.warn(currentIssue.getCustomFieldValue(19701))
Map jsonObj = [
"key" : currentIssue.getKey(),
"issueType" : currentIssue.getIssueType().name,
"status" : newStatus,
"Prichina" : currentIssue.getCustomFieldValue(16308).toString(),
"Shtat" : currentIssue.getCustomFieldValue(19700).toString(),
"Konkurent" : currentIssue.getCustomFieldValue(19701).toString()
]
try{
HttpResponseDecorator response = (HttpResponseDecorator) client.post(path: "",
contentType: JSON,
body: jsonObj,
//headers: [Accept: 'application/json',Authorization:"Basic ${authBasic}"]);
headers: [Accept: 'application/json']);
log.error("Status: " + response.status)
log.warn("requestBody: ${jsonObj}")
if (response.data) {
log.error("Content Type: " + response.contentType)
log.error("Headers: " + response.getAllHeaders())
log.error("Body:\n" + JsonOutput.prettyPrint(JsonOutput.toJson(response.data)))
//log.error("requestBody: ${jsonObj}")
}
}
catch(HttpResponseException e){
log.error e.getResponse().getData()
//log.error("requestBody: ${jsonObj}")
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.