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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where are you intending to run your script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.