Hi Team,
I need to update custom field's value on the current issue when we update system field's value on another issue.
We can take another issue as issueKey or also it is linked with suppose relates link type with outward link.
How we can do this using script listener?
Thanks!
Hey @Rahul
have you checked out the Adaptavist Library? This example seems to be quite close to what you want to achieve. I'm including it here in case the link gets broken in the future. I'd recommend reading it in their library because that's nicer formatted.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
// the name of the custom field to update
final customFieldName = 'Workaround'
def issue = event.issue
def change = event.changeLog.getRelated('ChildChangeItem').find { it.field == customFieldName }
// Was not the 'Workaround' field that changed, do nothing
if (!change) {
return
}
def linkedIssues = ComponentAccessor.issueLinkManager
.getOutwardLinks(issue.id)
.findAll { it.issueLinkType.name in ['Problem/Incident'] && it.destinationObject.issueType.name == 'Alert' }
// There are no linked 'Alerts' with 'Problem/Incident' link, do nothing
if (!linkedIssues) {
return
}
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.find {
it.name == customFieldName
}
def newWorkaround = """h4. Workaround - ${LocalDateTime.now().format(DateTimeFormatter.ofPattern('dd/MMM/yyyy HH:mm'))}<br>
${change.newstring}"""
linkedIssues.each {
def linkedIssue = it.destinationObject
def oldValue = linkedIssue.getCustomFieldValue(customField)
def newValue = newWorkaround + oldValue
customField.updateValue(null, linkedIssue, new ModifiedValue(oldValue, newValue), new DefaultIssueChangeHolder())
}
Cheers,
Matthias.
Thanks for the answer!
Can we update field's value without finding linked issues? Suppose we have another issue as issueKey and using issueKey only can we update the field's value on current issue from updating system field's value on another issue(as have issueKey).
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can search for other issues via JQL like this example states and then update the field inside the each loop.
Issues.search('project = SR and reporter = currentUser()').each { issue ->
// do something with `issue`
}
In your case, you could use a JQL like issuekey = ABC-123
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.