Hello,
I created a "Version" custom script field (used the code from the given link) which is supposed to count how many attachments we have, but it so happens that not every new uploaded attachment is an actual Version change. When attachment with the same name as previously uploaded documents are uploaded it means that only some minor cosmetical or grammatical corrections were needed in the document and I would need "Version" counter not to go up in that case. Is it possible somehow?
Cheers,
Rok
Hi Rok,
I think a solution in your problem would be instead of getting as a result the size of the list with all the attachments, to get the size of the list with unique attachments (an attachment with *exactly* the same name will not count twice)
def attachmentManager = ComponentAccessor.getAttachmentManager() def uniqueAttachmentsList = attachmentManager.getAttachments(issue).unique { it.filename } def numberAttachments = uniqueAttachmentsList.size() return numberAttachments ?: null
Hope that helps.
About the performance that @Mike Friedrich mentioned, the complexity of the groovy's unique() method is O(n^2), which means that may have performance issues on collections with lot of elements. If that is the case you can copy the list of all attachments to a Set (a collection that contains no duplicate elements) and then get the size of this Set as a result.
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.
I am assuming you have to modify the script yourself and compare the attachments. But I expect that feature to have unacceptable performance impacts.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
why?
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.