Hi,
I want to copy all attachment from task to linked issue during transition. I am using script runner to create the linked issue and i want to add the attachments from the task.
Please provide me with a script.
Thanks,
Swarna
Please refer below link, this may help
Hi,
I am getting error :
//iterate over the issues linked to the current issue through the "blocks" link type - change the link type as needed
for (Issue linkedIssue : issue.getLinkedIssues("relates to")) {
//add new attachments from linked issue
def linkedAttachments = linkedIssue.get("attachment")
for (Attachment linkedAttachment : linkedAttachments) {
//test if this attachment from the linked issue already exists on the current issue
if (!attachments.find{it.filename == linkedAttachment.filename && it.filesize == linkedAttachment.filesize && it.mimetype == linkedAttachment.mimetype})
//this attachment is new, copy it to the current issue
ComponentAccessor.attachmentManager.copyAttachment(linkedAttachment, currentUser, issue.key)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please let me know the error. what you are getting
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.
can you please include below at the top and try again
import com.atlassian.jira.issue.Issue
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.
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id);
def attachmentManager = ComponentAccessor.getAttachmentManager();
String commentAuthor = "currentUser"
def authorUser = (commentAuthor == "currentUser") ? ComponentAccessor.jiraAuthenticationContext.loggedInUser : ComponentAccessor.userManager.getUserByName(commentAuthor)
linkedIssues.each {
def linkedIssue = it.destinationObject
attachmentManager.copyAttachments(issue, authorUser, linkedIssue.key);
}
try above code, it will help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have tested the above code. No attachments are being copied.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please check whether you have add attachment permission on linked issues or not.
You can check logs for any error. or Add log statements to the code, you can find whether the issue is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have the permission to add attachments on linked issues. The script runs successfully. There is no error in the logs.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In this code , i am checking only outward links. can please check the links are outward or inward.
Other you can add log or system. out. println statement to check execution.
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id);
def attachmentManager = ComponentAccessor.getAttachmentManager();
String commentAuthor = "currentUser"
def authorUser = (commentAuthor == "currentUser") ? ComponentAccessor.jiraAuthenticationContext.loggedInUser : ComponentAccessor.userManager.getUserByName(commentAuthor)
System.out.println("Current issue" + issue.getKey());
System.out.println("linked issues size " + linkedIssues.size());
linkedIssues.each {
def linkedIssue = it.destinationObject
System.out.println("linked issue >>>>" + linkedIssue.getKey());
attachmentManager.copyAttachments(issue, authorUser, linkedIssue.key);
System.out.println("done");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Time (on server): Tue Aug 20 2019 10:52:04 GMT+0400 (Gulf Standard Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
No logs were found for this execution.
No logs are being found even I have changed Inwards and Outward linked
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.
Hi, I have added logs:
Time (on server): Wed Aug 21 2019 09:51:42 GMT+0400 (Gulf Standard Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2019-08-21 09:51:42,719 DEBUG [workflow.ScriptWorkflowFunction]: Current issue: CM-197 2019-08-21 09:51:42,720 DEBUG [workflow.ScriptWorkflowFunction]: linked issues size : 0
The linked issues size is 0 and for linkedIssue.getKey() there is no logs.
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id);
def attachmentManager = ComponentAccessor.getAttachmentManager();
String commentAuthor = "currentUser"
def authorUser = (commentAuthor == "currentUser") ? ComponentAccessor.jiraAuthenticationContext.loggedInUser : ComponentAccessor.userManager.getUserByName(commentAuthor)
System.out.println("Current issue" + issue.getKey());
log.debug "Current issue: ${issue.getKey()}"
System.out.println("linked issues size " + linkedIssues.size());
log.debug "linked issues size : ${linkedIssues.size()}"
linkedIssues.each {
def linkedIssue = it.destinationObject
System.out.println("linked issue >>>>" + linkedIssue.getKey());
log.debug "linked issue >>>>: ${linkedIssue.getKey()}"
attachmentManager.copyAttachments(issue, authorUser, linkedIssue.key);
System.out.println("done");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The reason why you get 0 for the size is because of getOutwardLinks. Try getInwardLinks instead.
This is how we are copying the attachments from the source issue to a newly created linked issue:
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
def linkedIssuesOutward = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id);
def linkedIssuesInward = ComponentAccessor.issueLinkManager.getInwardLinks(issue.id);
def attachmentManager = ComponentAccessor.getAttachmentManager();
log.setLevel(Level.DEBUG)
log.info "Current issue: " + issue.key
log.info "linked issues outward size: " + linkedIssuesOutward.size()
log.info "linked issues inward size: " + linkedIssuesInward.size()
linkedIssuesInward.each {
def linkedIssue = it.sourceObject
log.info "linked issue >>>>: ${linkedIssue.getKey()}"
attachmentManager.copyAttachments(linkedIssue, issue.creator, issue.key);
}
I hope this helps.
Kind regards,
Daphnis
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.