Hey guys,
Jira users want to see the list of attachments based on reverse time. My code is
if (attachments){
for (attachment in attachments.reverse()) {
if(count>0){
text+='\n'
}
text+= attachment.getCreated().format('dd/MM/yyyy HH:mm:ss') + ": " + attachment.getId().toString()
count+=1
}
def rendererManager = ComponentAccessor.getComponent(RendererManager.class)
def fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem("attachment")
def renderer = rendererManager.getRendererForField(fieldLayoutItem)
renderer.render(text, null)
}
The result is:
Timestamp Id
------------ -----
22/02/2022 21:49:07: 17354
22/02/2022 21:49:12: 17353
22/02/2022 21:49:09: 17352
Which means the order is based on attachment id. Please, how can I order them based on creation time? Thanks!
Almu
Finally, I got it
def attachments = ComponentAccessor.getAttachmentManager().getAttachments(issue)
def latestAttachment = attachments.findAll().sort { it.created }.reverse()
def count=0
def text=""
if (attachments){
for (attachment in latestAttachment) {
if(count>0){
text+='\n'
}
text+= attachment.getCreated().format('dd/MM/yyyy HH:mm:ss') + ": " + attachment.getId().toString()
count+=1
}
def rendererManager = ComponentAccessor.getComponent(RendererManager.class)
def fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem("attachment")
def renderer = rendererManager.getRendererForField(fieldLayoutItem)
renderer.render(text, null)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Almu ,
Are you expecting the result like this?
22/02/2022 21:49:07: 17354
22/02/2022 21:49:09: 17352
22/02/2022 21:49:12: 17353
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sachin,
Thanks for your swift reply.
Actually in reverse time:
22/02/2022 21:49:12: 17353
22/02/2022 21:49:09: 17352
22/02/2022 21:49:07: 17354
Cheers,
Almu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Almu ,
Normally the order of attachment creation should match with the attachment ID.
I checked some of the attachment and their ID is matching with creation date order.
Regarding the Groovy Script - I was thinking cant we store this date timestamp information in List and sort it down in reverse order like we do the with numbers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sachin,
Thanks again for your interest. Finally, I got it with
def latestAttachment = attachments.findAll().sort { it.created }.reverse()
Cheers,
Almu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.