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.ChangeItemBeanimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.link.IssueLink;import com.atlassian.jira.component.ComponentAccessor;def customFieldManager = ComponentAccessor.getCustomFieldManager()int cfId = 11002def 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 valuecf.updateValue(null, linkedIssue, new ModifiedValue(linkedIssueCfValue, cfParentValue), new DefaultIssueChangeHolder())// Updates with current issue valuecf.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
Hi @Antoine Berry
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
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.Issueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.component.ComponentAccessor;def customFieldManager = ComponentAccessor.getCustomFieldManager()int cfId = 11002def 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)}
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
It looks like you're new here. Sign in or register to get started.