Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Custom field's value update on current issue when updating system field's value on another issue

Rahul August 13, 2024

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!

1 answer

1 accepted

1 vote
Answer accepted
Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 13, 2024

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.

Rahul August 14, 2024

Hi @Matthias Gaiser _K15t_ 

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!

Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 14, 2024

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 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

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
AUG Leaders

Upcoming Jira Events