Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

I want to create an issue with a Proforma/Forms attached using groovy

Michael June 21, 2024

I am trying initially to use Scriptrunner hapi to create an issue with a proforma form attached, I am happy to not use HAPI if theres no option but i want to create a JSM ticket with a pre-created Proforma form attached but i cannot seem to get it to work. Proforma forms are listed in the Entity property of an issue so I am trying to add the form using setProperty Method but anything i attempt does not work (creates issue but not attach the form)

Please help


 

Issues.create("TEST","TASK") {    

setSummary("IM HAPI")    

setRequestType("Test Request")    

setReporter("Test User")    

//Try to set property not sure how to get this line to work

setProperty(proformaKey, proformaValue)    

}

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Chris Melville June 21, 2024

Here is some sample code that attaches a form.  You need to select the proper template Form ID and add your own PAT.  I don't know if there is a way to do it with HAPI, this was the best I could come up with.

import groovy.json.StreamingJsonBuilder

def issuekey = 'PROJ-1234'
def body_req = [ "templateFormId": 2 ]
def baseURL = "https://my.jirainstance"
def url = new URL(baseURL + '/rest/proforma/1/issue/' + issuekey + '/form')
String jiraToken = "Bearer personal_access_token_goes_here"

URLConnection connection = url.openConnection()
connection.requestMethod = "POST"
connection.doOutput = true
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.setRequestProperty("Authorization", jiraToken)
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect()

log.warn("url: " + url)
log.warn("Content:" + connection.getContent())
log.warn("ResponseCode:" + connection.getResponseCode())
log.warn("getResponseMessage:" + connection.getResponseMessage())
Michael June 24, 2024

Thanks @Chris Melville 

I had thought initially to use REST which I think would work using your code but ideally if possible I would like to create the issue with the form attached, and not create the issue then call rest to add the form in later (in case there is any issue with the rest call, and for my use case that would make the newly created issue redundant but if this is the only way we may have to down this route) however I am not sure if it is possible to create an issue with the form attached but there is little to no documentation of how to do this using the Java API.

TAGS
AUG Leaders

Atlassian Community Events