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,539
Community Members
 
Community Events
176
Community Groups

How to update a custom field value from parent issue into linked issue

Hi,

 

I'd like to update a custom field value from parent issue into linked issue.

However, I didn't managed to update the linked issues although I got the linked issue list.

Followed my script:

 

long linkId = 10302
long FIELD_ID3 = 13007

def issueManager = ComponentAccessor.getIssueManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf3 = customFieldManager.getCustomFieldObject(FIELD_ID3)
def cf3Value = issue.getCustomFieldValue(cf3)

def inwardLinks = issueLinkManager.getInwardLinks(issue.id)
def links = ""

inwardLinks.each {
    if(it.getLinkTypeId() == linkId){
        links += "${it.getSourceObject().getKey()}<br/>"

    }
}
Kindly,
Gilad

1 answer

0 votes
Tom Lister Community Leader Dec 12, 2022

Hi @Gilad Shtern 

You will need to process the update within your code. This an example from
https://github.com/listertuk/groovy/blob/2ded1edab2bdf4c266ee2fb4720a827ddf4effd8/server-dc/Scriptrunner/LDAP/ChangeAssigneesReportersInListCheilEU.groovy

 

 

import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.component.ComponentAccessor

def logit = Logger.getLogger('com.domain1.logging')
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService issueService = ComponentAccessor.issueService
def issueId = 100300
def customFieldId = 10100
Issue issue = issueService.getIssue(user, issueId).getIssue()
//or
//IssueManager issueManager = ComponentAccessor.getIssueManager()
//Issue iss = issueManager.getIssueByCurrentKey("ACP=120")

def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setSkipScreenCheck(true)
issueInputParameters.addCustomFieldValue(customFieldId, "value")
UpdateValidationResult updateValidationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)
if (updateValidationResult.isValid()) {
IssueResult updateResult = issueService.update(user, updateValidationResult)
if (!updateResult.isValid()) {
// report error
}
}



Hi @Tom Lister ,


Thank you for this tip.
However, it seems like script is very slow.

Still, I'm not sure how to update the linked issues.
Meaning, I've linked issue list, but I can't extract CF update as one by one.

Kindly,
Gilad

Tom Lister Community Leader Dec 13, 2022

Hi @Gilad Shtern 

Where are you intending to run your script?

Hi @Gilad Shtern 

In your code you have the list of inward links. And within the inwardlinks loop you can access the other side of the link using

Issue issue = it.getDestinationObject()
or just get the id it.getDestinationId()

(or it.getSourceObject or id if inward links are defined the other way around)

Looks like you already know your internal field id and method on the issueInputParameters.addCustomFieldValues only needs the id and value.

Or are you saying you would like to fire off a bulk update based on the links list?

re Slow - I'll test it out on my server. The issue service methods will ensure the update follows any conditions that would happen if you input data via a screen so may be a bit more involved but much safer. I wouldn't expect it to be any slower that a manual bulk update.

Tom Lister Community Leader Dec 13, 2022

Hi @Gilad Shtern 

This works on my server in the Script Console and seems quite fast.

 

import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def logit = Logger.getLogger('com.domain1.logging')
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService issueService = ComponentAccessor.issueService
def issueId = "SCR-10"
def customFieldId = 10200 // Text field

Issue issueIn = issueService.getIssue(user, issueId).getIssue() // get issue from issueservice.IssueResult
logit.info issueIn.key
def outwardLinks = issueLinkManager.getOutwardLinks(issueIn.id)
//def links = ""

outwardLinks.each {
//if(it.getLinkTypeId() == linkId){
//links += "${it.getSourceObject().getKey()}<br/>"
logit.info it.getDestinationObject().getKey()

Issue issue = it.getDestinationObject()

// }

def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setSkipScreenCheck(true)
issueInputParameters.addCustomFieldValue(customFieldId, "value")
UpdateValidationResult updateValidationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)
logit.info updateValidationResult.isValid()
if (updateValidationResult.isValid()) {
IssueResult updateResult = issueService.update(user, updateValidationResult)
logit.info updateResult.isValid()
if (!updateResult.isValid()) {
// report error
logit.info updateResult.getErrorCollection().toString()
}
}
}

Suggest an answer

Log in or Sign up to answer