Copy table from parent to child issue on transition with Scriptrunner

Copy table from parent to child issue on transition with Scriptrunner

def sourceIssueKey = "IN-2" // in Post-Function use 'issue.key' def targetIssueKey = "IN-7" // You know where to put it ;) def tableFieldId = "309" // recive id from App/Field config final externalUrl = "https://apps.stagil.com/stjc/rest/stj/1.0/api/table" def issueObj = get("/rest/api/3/issue/{issueKey}") .routeParam("issueKey", sourceIssueKey) .asObject(Map).body def sourceTable = get("${externalUrl}/customField/{field}/issue/{issueKey}") .routeParam("issueKey", sourceIssueKey) .routeParam("field", tableFieldId) .basicAuth(STAGIL_TABLELS_API_USERNAME, STAGIL_TABLELS_API_TOKEN) .header("accept", "application/json") .asObject(Map).body sourceTable.get("data").each{ def row -> logger.warn "${row.id}" logger.warn "${row.getClass()}" def ignoreredKeys = [] row.each{ if (!(it.getKey() ==~ "field-\\d*")){ ignoreredKeys.add(it.getKey()) } } ignoreredKeys.each{ row.remove(it) } def json = JsonOutput.toJson(row) logger.warn "$json" def targetRow = post("${externalUrl}/customField/{field}/issue/{issueKey}") .routeParam("issueKey", targetIssueKey) .routeParam("field", tableFieldId) .basicAuth(STAGIL_TABLELS_API_USERNAME, STAGIL_TABLELS_API_TOKEN) // define your credentials in Scriptrunner Variables .header("Content-Type", "application/json") .header("accept", "application/json") .body(json) .asJson() } return sourceTable