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
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:
def issueService = ComponentAccessor.issueService
def issue = event.issue as Issue
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def projectAKeyCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('ProjectA-Key')
def changeRequestCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Change Request')
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
Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events