I am trying to copy the value of a custom field from the linked issue. It works good with one to one link but doesnt work when they have the same issue linked to multiple issues. Example: Ab is the project where the scripted field is present, XY is a project where the value is present when Ab-1 and Ab-2 has link with XY-1 the script works for only Ab-1 but Ab-2 is null. Any help appreciated
Here is a script that will copy the values from a Custom Field into the Linked Issues' Custom Fields:
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())
}
}
Hi,
the script works fine with multiselect fields, but how do I get it to work with Singe User Picker custom fields?
best regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @[deleted] ,
Have you found the solution for your question?
Can come one please help?
Regards,
Anuradha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Avinashhave you been able to create the script?
I also need a script which copies Region field value from linked issue to Region field of the issue where the link was created.
Can you share it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, What type of field in JIRA is region field value ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi. Its a Select List (single choice) custom field.
I have the following setup:
When I link Support ticket to Survey ticket (from Survey ticket), I need to pull the Support ticket Region field value and update the Survey ticket Region field value.
Thanks for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think your only reference to issue (the current issue, AB-1 or AB-2) is where you're assigning linkedTasks's initial value. That leads me to believe that there could be some sort of flaw in the logic. Are you sure AB-2 has the same direction of link at AB-1?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.