Hi everybody,
I'm working on a project where I have two workflows. One for the main ticket and one for the many subtasks that can be created during the main ticket resolution process.
When I close a subtask I have a screen with an "attachment" field allowing the users to add a document to the subtask and with the help of a script the document is also added to the main ticket.
It's working fine.
The problem occurs if I re-open a subtask to which a document has been attached on the "close" transition. When I will close this subtask again, the attachment I added the first time will be added again in the main ticket. So I have the same document two times in the main JIRA. That's a big problem for my project.
So I tried to add a "clear field value" script on "attachment" field on the "close" transition (after the script that send the attachment to main JIRA of course) but it doesn't works.
I use the "clear field value" script on many transitions to reset te values of many fields and it works perfectly. The problem only concerns the "attachment" field. For example it works perfectly with the "assignee" field and "delivery date" field.
When I try to purge the ttachment field an error occurs and JIRA send a message advertising me that the transition is impossible to execute.
You can see the screenshot below:
I tried on different transition. Even on transition of the main ticket workflows. I still got the same error.
Do you have any idea on how I can "purge" the attachment field?
I'm using script runner 5.1.6 and JIRA 7.2.0
Thanks in advance!
Regards,
Germain.
Hi Germain,
I think a slightly different approach will help you solve this. What if you just modify the script that is used to copy an attachment from a sub-task to its parent so that if there's already an attachment in the parent issue with the EXACT SAME name then the attachment from the sub-task will not be copied? Would that work for you?
Hi Ivan,
It's a great idea but in my context it will not work as users will sometimes re open a subtask to modify what's inside the attachment but not the name. I need to allow them to send the same name attachment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem, let's add a file size check, to be extra safe. Sure, it's not 100% bulletproof, but I have a feeling that a scenario where a file will have an EXACT size of the original after the edits is VERY unlikely.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's another great idea. I will ask my management but I'm pretty sure they will tell me it's not a "safe" enough solution.
I keep you up to date.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In fact that's a solution that my management would accept!
So, Ivan, how would you write the script to compare name and size of the subtask's attachment and attachments already in the main ticket?
I want to allow the attachment to be added to main ticket if attachment's name is different of attachments in main ticket or if attachment's size is different if name is the same.
For information, here is the script I use to get the attachment (Yes, it's your code ^^):
def attMgr = ComponentAccessor.getAttachmentManager()
def attachments = attMgr.getAttachments(issue)
def parentAttachments = attMgr.getAttachments(parentIssue)
def lastAtt = attachments[0]
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if (attachments.size() < 1){
for (int i = 1; i < attachments.size(); i++){
if (lastAtt.getCreated().getTime() < attachments[i].getCreated().getTime()){
lastAtt = attachments[i]
}
}
}
attMgr.copyAttachment(lastAtt, currentUser, issue.getParentObject().getKey())
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Right, let's get this show on the road, shall we? Try this:
import com.atlassian.jira.component.ComponentAccessor
def attMgr = ComponentAccessor.getAttachmentManager()
def attachments = attMgr.getAttachments(issue)
def parentAttachments = attMgr.getAttachments(issue.getParentObject())
def lastAtt = attachments[0]
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if (attachments.size() > 1){
for (int i = 1; i < attachments.size(); i++){
if (lastAtt.getCreated().getTime() < attachments[i].getCreated().getTime()){
lastAtt = attachments[i]
}
}
}
boolean sameFileExists = false
if (parentAttachments.size() > 0){
for (int i = 0; i < parentAttachments.size(); i++){
if (lastAtt.getFilename() == parentAttachments[i].getFilename() && lastAtt.getFilesize() == parentAttachments[i].getFilesize()){
sameFileExists = true
}
}
}
if (sameFileExists == false){
attMgr.copyAttachment(lastAtt, currentUser, issue.getParentObject().getKey())
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ivan,
That's perfect, it works on first try!
It's a really good point for my project.
Thank you very much :)
Regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.