Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Anuradha Yadav September 11, 2022

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