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())
}
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
}
Hellow @Graham Twine,
I apologize for the delay in replying.
Don't works, so i abandoned the idea and think in another solution.
State point
1- This listener it's Ok
// Events: Issue Commented; Issue Comment Edited; Issue Comment Deleted. And have a custom Field "Last Comment New Version":
I already managed to solve:
Event: "issueLinkCreated" instead of "Issue Created"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Isabel Fonseca ,
def comment = commentManager.getLastComment(issue)
I think you are looking to inspect the cloned issue.
issue is coming from the original issue at event.issue. This is correct issue is the original issue and not the cloned issue.
def comment = commentManager.getLastComment(clonedIssues.get(0))
The example I have shared above is a bit naive as it blindly grabs the first issue from the list.
clonedIssues is a collection of issues that contains 0 to n depending on the number of outward links from the original issue of type "clones" as defined by "findAll"
This may be fine for your use case but it may be worth logging the result
def clonedIssues = ComponentAccessor
.issueLinkManager
.getOutwardLinks(issue.getId())?
.findAll {it.issueLinkType.outward == "clones"}
log.info("Found ${clonedIssues?.size()} clones with outward links to issue ${issue.key}"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'll look into it, thank you very much.
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.