Good afternoon,
I have a situation in jira in Listener, which I need help with.
Current solution ScriptRunner\ Listenner (Events: Issue Commented, Issue Comment Edited, Issue Comment Deleted):
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
// Set log level to INFO
log.setLevel(Level.INFO)
def issue = event.issue
def commentManager = ComponentAccessor.commentManager
def comment = commentManager.getLastComment(issue)
def customFieldManager = ComponentAccessor.customFieldManager
// Get the custom field
def customField = ComponentAccessor.customFieldManager.customFieldObjects.findByName("Last Comment")
if (comment) {
comment.body
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), comment.body), new DefaultIssueChangeHolder())
} else {
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), ""), new DefaultIssueChangeHolder())
}
Test failure: Basically, when I have issua A with comment(s), and I clone it, it creates issue B.
PROBLEM: When I search for issues, in the list resulting from the search, in the column “Last Comment” the last comment appears in issue B but referring to issue A. It should appear empty, because issue B has no comments.
I've already investigated and found some solutions, but it ends up generating other problems in the combinations of possible actions on comments.
Resolution attempt:
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.search.SearchException
// Set log level to INFO
log.setLevel(Level.INFO)
def issue = event.issue
def customFieldManager = ComponentAccessor.customFieldManager
// Get the custom field
def customField = ComponentAccessor.customFieldManager.customFieldObjects.findByName("Last Comment")
def clonedIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())?.findAll {it.issueLinkType.outward == "clones"}
try {
if (!clonedIssues) {
log.warn('CLONE no.')
def commentManager = ComponentAccessor.commentManager
def comment = commentManager.getLastComment(issue)
if (comment){
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), comment.body), new DefaultIssueChangeHolder())
} else {
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), ""), new DefaultIssueChangeHolder())
}
} else {
log.warn('CLONE yes.')
def commentManager = ComponentAccessor.commentManager
// fails on next line if it comes from clone. Because it brings comment from the original issue, not the clone !!!
def comment = commentManager.getLastComment(issue)
if (comment){
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), comment.body), new DefaultIssueChangeHolder())
} else {
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), ""), new DefaultIssueChangeHolder())
}
}
} catch (SearchException e) {
e.printStackTrace()
null
}
I can't identify this “clone” action to load comment with nothing (because it catches issue A and not B, line 70 in Resolution attempt )
Do you have any suggestions?
Best Regards,
Isabel Fonseca