Hi guys,
I have a scriptrunner post function that get the list of the attachment of an issue, and I need to take the last added attachment and read the content. The problem is that I don't know ho Jira organize the attachment and the script not always get the last Attachment.
I use a For Cicle to get all the attacchment and I use the lenght of the attachment in the issue(minus 1) to get the last one attachment, but the last one that resti api get is not the last one In order of date I have added.
This is my code:
def result2 = get('/rest/api/2/issue/FWT-307?fields=attachment')
.header('Content-Type', 'application/json')
.asObject(Map)
Map mappa = result2.body.fields as Map
logger.info(mappa.attachment as String)
def attLenght = (mappa.attachment as Map).size()
if(attLenght > 0 && attLenght <= 30){
mappa2 = (mappa.attachment as Map).get(attLenght-1)
logger.info("MAPPA2"+ (mappa2 as String))
idCSV = mappa2.id as String
logger.info(mappa2.id as String)
logger.info(mappa2.content as String)
contentCSV = mappa2.content as String
with this logger.info at the end I check that I don't get the Last Attachment i have added but another Attachment, I don't know how Jira organize the Attachment Order.
How to get always the last Attachment order by Date?
Thanks