I am attempting to get rest data for the Tempo Account field in an epic and put the "name" of the received data into a newly linked issue. I am not good with REST
I am using ScriptRunner Listener listening for the IssueLinkCreatedEvent. Below is the code I am using so far.
/*
Fires when a Issue Link is created.
Exits if Linked to Issue is not Initiative / Feature / Epic
Copies Custom Fields down from Linked Issue
*/
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper
// Change Logger
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.INFO)
// Setup Custom Field Manager
def CustomFieldManager = ComponentAccessor.getCustomFieldManager()
// Setup Issue Manager
def IssueManager = ComponentAccessor.getIssueManager()
/**
Grab both target and source issue objects from the event
*/
// Grab Event
def event = event as IssueLinkCreatedEvent
// sourceIssue is really the Issue that is being Linked to.
def sourceIssue = event.getIssueLink().getSourceObject()
log.info("sourceIssue: " + sourceIssue.key)
// Exit if not Initiative / Feature / Epic
if (sourceIssue.issueType.name != "Epic"){
log.info("Exiting ... sourceIssue type of"+sourceIssue)
}
// Which makes the Destination object really the issue
def issue = event.getIssueLink().getDestinationObject()
log.info("issue: " + issue.key)
// define ChangeHolder Object
def changeHolder = new DefaultIssueChangeHolder();
/**
Account Section
*/
// setup CfAccount field object
def CfAccount = CustomFieldManager.getCustomFieldObject('customfield_14601')
log.info("CfAccount: " + CfAccount)
//Set base URL for Jira Instance
def JIRA_URL = "https://jira/"
//Rest Account Field API
def ACCOUNT_API = "/rest/tempo-accounts/1/account/issue/${issue}/current/"
//EPIC Account Field API
def EPIC_API = "/rest/tempo-accounts/1/account/issue/${sourceIssue}/current/"
//Set Full REST API to grab Account from EPIC
def GET_REST_API = JIRA_URL+EPIC_API
log.info("Full Rest URL: " +GET_REST_API)
//Destination to Post rest data
def DEST_REST_API = JIRA_URL+ACCOUNT_API
log.info("Desintation Rest URL: "+DEST_REST_API)
def http = new HTTPBuilder(JIRA_URL)
http.request(GET){
def requestContentType = ContentType.JSON
def body = [name: ]
}
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.