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

Scripted Field to copy custom field (Link picker field) from Linked Issues

Hi Team,

 Trying to copy the value of a custom field from the linked issue. The field we have here is Link picker field.

We have this field for  multiselect fields. But could some one help me to modify this script for Link picker field? As I am new to this Script.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueLinkManager = ComponentAccessor.issueLinkManager
def issueManager = ComponentAccessor.issueManager
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def issue = issueManager.getIssueByCurrentKey('JRA-2') // change this to match your main issue key
def customField = customFieldManager.getCustomFieldObjectsByName('MultiSelectA')[0] // change this to match your custom field name

def customFieldValue = issue.getCustomFieldValue(customField)
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()

def linkedIssues = issueLinkManager.getLinkCollection(issue, currentUser).getAllIssues()

for (int i = 0; i < linkedIssues.size(); i++) {
log.debug("Updating issue: ${linkedIssues[i]}")

// This is for the Multi Select List. It will change if you work with another type of Custom Field
// For example, you won't have to loop through a text field, you would just pass what was in customFieldValue
def values = customFieldValue.collect{ Option option ->
option.optionId.toString()
}

issueInputParameters.with {
addCustomFieldValue(customField.idAsLong, *values) // *values is something Groovy does to destruct a list into plain arguments
}

def updateValidationResult = issueService.validateUpdate(currentUser, linkedIssues[i].id, issueInputParameters)

if (updateValidationResult.isValid()) {
def finalUpdateResult = issueService.update(currentUser, updateValidationResult)
log.debug(finalUpdateResult.errorCollection)
log.debug(finalUpdateResult.warningCollection.getWarnings())
log.debug(finalUpdateResult.isValid())
} else {
log.debug(updateValidationResult.errorCollection)
log.debug(updateValidationResult.warningCollection.getWarnings())
}

}

 

Regards,

Anuradha

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events