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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,724
Community Members
 
Community Events
176
Community Groups

How to update a custom field of another issue by getting the issue from Custom field

Hi,

I have 2 Projects. Project A and Project B.  Project B has a Custom Field called "ProjectA- Key" The Key of Project A that relates to project B is copied into the "ProjectA-Key" field. 

I have another field called "Change Request"

I will like to write a listener script that copies the Change Request field on Project B to Project A when an update event happens in Project B by looking up the Key entered in the "ProjectA-Key" field to get the Project A issue to be updated with the value from Project B

 

 

1 answer

0 votes

It would help to know the type of each of those custom fields and see more concrete examples.

Also, does ProjectA-Key contain a project key? Or does it contain an issue key that happens to belong to Project A?

But something like this should put you on the right track:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def issueService = ComponentAccessor.issueService
def issue = event.issue as Issue
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def projectAKeyCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('ProjectA-Key')[0]
def changeRequestCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Change Request')[0]
def projectAKey = issue.getCustomFieldValue(projectAKeyCf)
def changeRequest = issue.getCustomFieldValue(changeRequestCf)

def projectAIssue = ComponentAccessor.issueManager.getIssueObject(projectAKey as String)

def iip = issueService.newIssueInputParameters()
iip.addCustomFieldValue(changeRequestCf.id, changeRequest as String)
def validationResult = issueService.validateUpdate(currentUser, projectAIssue.id, iip)
assert validationResult.valid, validationResult.errorCollection
def updateResult = issueService.update(currentUser, validationResult)
assert updateResult.valid, updateResult.errorCollection



Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events