Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi,
Keep in mind you need criterias to define which linked issue to update. This snippet will get all the linked issues (inward and outward) of the current issue. I added some logs so you can decide which criteria to apply, and an example of updating the custom field value with current issue value or parent issue value.
Do not forget to update custom field id.
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
int cfId = 11002
def cf = customFieldManager.getCustomFieldObject(cfId)
def cfValue = issue.getCustomFieldValue(cf)
def cfParentValue = issue.getParentObject().getCustomFieldValue(cf)
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
def linkedIssue = issueLink.getDestinationObject()
def linkedIssueTypeName = issueLink.getIssueLinkType().getName()
def linkedIssueCfValue = linkedIssue.getCustomFieldValue(cf)
log.debug("issueLink : " + issueLink.getIssueLinkType().getName())
log.debug("linkedIssue : " + linkedIssue)
log.debug("linked issue type : " + linkedIssue.getIssueType().getName())
if (linkedIssueTypeName == "Cloners"){
//Updates with parent issue value
cf.updateValue(null, linkedIssue, new ModifiedValue(linkedIssueCfValue, cfParentValue), new DefaultIssueChangeHolder())
// Updates with current issue value
cf.updateValue(null, linkedIssue, new ModifiedValue(linkedIssueCfValue, cfValue), new DefaultIssueChangeHolder())
}
}
List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> inIterator = allInIssueLink.iterator(); inIterator.hasNext();) {
IssueLink issueLink = (IssueLink) inIterator.next();
def linkedIssue = issueLink.getSourceObject()
def linkedIssueTypeName = issueLink.getIssueLinkType().getName()
log.debug("issueLink : " + issueLink.getIssueLinkType().getName())
log.debug("linkedIssue : " + linkedIssue)
}
Antoine
I am trying to update child value from parent ticket itself. So in your code will cf.updateValue update the customfield in child ticket? I think it will check in current issue whereas the field exists only in linked ticket not in parent ticket
I am trying to set a customfield value for a date field in the linked ticket as below
IssueLinkManager linkManager = ComponentAccessor.getIssueLinkManager();
List<IssueLink> issueLinks = linkManager.getOutwardLinks(issue.getId());
for(IssueLink link : issueLinks) {
log.debug("link name " +link.getDestinationObject().getStatus().getName())
if (link.getIssueLinkType().getName().equals("XXX)")){
Issue duplicateTicket = link.getDestinationObject();
duplicateTicket.setCustomFieldValue(plannedregDate,issue.getCustomFieldValue(plannedrcdate))
Is there anything I am missing
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you are confusing issue links and parent to child links. They are different :
Updating a sub-task is easier :
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.component.ComponentAccessor;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
int cfId = 11002
def cf = customFieldManager.getCustomFieldObject(cfId)
def cfValue = issue.getCustomFieldValue(cf)
for (Issue subtask:issue.getSubTaskObjects()) {
log.debug("sub task key : : " + subtask.getKey())
log.debug("sub task issue type : : " + subtask.getIssueLinkType().getName())
def subTaskCfValue = subtask.getCustomFieldValue(cf)
cf.updateValue(null, subtask, new ModifiedValue(subTaskCfValue, cfValue), new DefaultIssueChangeHolder())
log.debug("updating customfield " + cf + " of issue " + subtask + " with value " + cfValue)
}
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am working with issue links not the subtask.
So in your code, cf.updateValue().. this customfield doesnt exist on the ticket from which i am writing the code.
So will this method go and update the value in the linked ticket? I was assuming cf.UpdateValue will update in the current ticket
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
cf.updateValue(null, issue, new ModifiedValue(oldValue, newValue), new DefaultIssueChangeHolder())
updates the custom field value on the issue "issue" from "oldValue" to "newValue". Now replace these with whatever you want.
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.
Hey @Antoine Berry
How are u?
Along these lines, I can do something like this:
Issue parent has "N" issue child linked to it.
In the issue child I have a field X that registers hours (It's a sigle line text field) and in the issue parent I have a field that needs to receive the result of the sum of hours pointed in the issue child field.
Ex: Field Issue parent____ ?h
Field Issue child____2h
Field Issue child____2h
Field Issue child____2h
Issue child time result = 6h <--- This result must appear there in the parent issue.
Can you help me?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Raphael Henrique Fernandes Lopes ,
Could you please create a new question (you can ping me on it) ? This way everyone will be able to help you.
This is definitely possible, however I would probably advise to use a numeric field instead of a text field.
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.