Please help. I need to send list of attachments as a String to external source.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.attachment.Attachment
import groovy.json.JsonOutput
import java.net.HttpURLConnection
import java.net.URL
def issue = issue
def attachmentLink = ""
def apiToken = "______________________________________"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def attachmentManager = ComponentAccessor.getAttachmentManager()
List<Attachment> attachments = attachmentManager.getAttachments(issue)
attachments.each {attachment ->
attachmentLink += "_____________________________________________________________"
}
def getCustomFieldValueById({{issue.customfield_16600}}) {
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(fieldId)
if (customField) {
return issue.getCustomFieldValue(customField)
}
return null
}
getCustomFieldValueById()
def updateContext(elmaAppId, attachmentLink) {
def elmaUrl = "________________________________________________"
def payload = [
ssylka_na_dogovor_tkp: attachmentLink
]
def url = ner URL(elmaURL)
def connection = url.openConnection() as HttpURLConnection
connection.requestMethod = "POST"
connection.doOutput = true
connection.setRequestProperty("Authorization", "Bearer ${apiToken}")
connection.setRequestProperty("Content-Type", "application/json")
connection.setRequestProperty("Accept", "application/json")
def outputStream = connection.outputStream
outputStream.write(JsonOutput.toJson(payload).getBytes("UTF-8"))
outputStream.flush()
outputStream.close()
}
updateContext(getCustomFieldValueById(), attachmentLink)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.