You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.