Hi everybody,
I'm working on a project with 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.
Using the script below I can copy the attachment that is entered in the attachment field to the attachment field in the main ticket.
import com.atlassian.jira.component.ComponentAccessor
def cwdUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def attMgr = ComponentAccessor.getAttachmentManager()
def attachments = attMgr.getAttachments(issue)
def parentAttachments = attMgr.getAttachments(issue.getParentObject())
def lastAtt = attachments[0]
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, cwdUser, issue.getParentObject().getKey())
}
The script is perfectly working.
Now, I would like a validator that will compare the attachment that is entered in the attachment field of the close subtask transition with the existing subtasks in the main ticket. If the new attachment has the same name than one of the attachment in the main ticket I would like the validator to shoot a warning message and block the transition.
Do you have any idea on how to manage that?
Thanks in advance.
Regards.
Germain.