Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Linking in Plans does not trigger "Issue Updated" automation rule.

Michael Wu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 20, 2023

We have a complex structure in Plans, I have a rule to copy certain field values in "Child" issues when I link an Epic to an Initiative.
When I link in Plans, the Epic is updated with new "Parent Link" value, but the Initiative (in this case the Parent) has no update (even issue history does not show this change) and therefore does not trigger the rule with "Issue Updated" trigger. I need the Initiative (parent) to be the trigger issue since I am using "Copy field value from trigger issue" to edit the Epic (child). I need this to be the case because if I use the Epic as a trigger then copying values using {{issue.parent.customfield_xxxxx.value}} and {{issue.Parent Link.customfield_xxxxx.value}} does not work.

I have a workaround already which involves two rules and works as follows:

Rule 1: Issue updated > IF "Parent Link" is not EMPTY > Branch Rule JQL: issuekey = {{issue.Parent Link}} > Add comment

Rule 2 (Allowed trigger from other rules): Issue commented > Branch Rule JQL: "Parent Link" = {{issue.key}} > Edit Issue: copy fields.

BUT these don't cover cases where links exist and the field values are changed, I will probably need another rule for it.

All of this could be avoided if the parent was updated when linked through Plans, does anyone know why linking through plans does not update the parent? or a way to trigger the update event?

 

1 answer

1 accepted

0 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 24, 2018

Hi Edwin,

Yes, those still work. What are you trying to accomplish with your script? Can you post your entire script here? The server side script will be ran once when the form is loaded and then every single time the field is changed.

Regards,

Josh

Edwin Ruiz
Contributor
October 24, 2018

So I currently have this code linked to the Epic Link field. It works as intended but not firing when i want it to, which is after the user has finished making changes (hit the Update button). 

What I am trying to accomplish is adding a label to (parent) epic the ticket is linked to. I currently have similar code in the workflow for when a ticket is transitioned but a workflow doesn't account for when a ticket is linked manually to an epic as that is not changing a ticket status.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.label.Label;
import com.atlassian.jira.exception.DataAccessException;

// get an issue manager to deal with issues (getting and setting fields)
def issueManager = ComponentAccessor.getIssueManager();
def userManager = ComponentAccessor.getUserManager();
def me = userManager.getUserByName("testuser")
def issue;
Set<Label> labelsSet = new HashSet<Label>();
// get value in epic link field
String epic = getFieldById("customfield_10006").getValue();
String issueKey, issuesString;
if(getActionName() == null && epic != "null"){

issueKey = epic.substring(epic.indexOf(":")+1)

try{
issue = (MutableIssue) issueManager.getIssueByCurrentKey(issueKey);
} catch (DataAccessException e){
return;
}

def linkManager = ComponentAccessor.getIssueLinkManager();
def listTickets = linkManager.getOutwardLinks(issue.getId())

def allDone = true
for (IssueLink link : listTickets) {
// we only care about tickets in epic
if (link.getIssueLinkType().getName() == "Epic-Story Link"){
// only 1 tickets needs to not be done for the epic to not be done
if(link.getDestinationObject().getStatus().getName() != "Done"){
allDone = false;
}
}
}

labelsSet.addAll(issue.getLabels());

Label epicDone = new Label(91185L, issue.getId(), "epic-done")

if (allDone){
labelsSet.add(new Label(91185L, issue.getId(), "epic-done"))
}else{
for (Label label: labelsSet) {
if (label.getLabel() == "epic-done") {
labelsSet.remove(label);
}
}

}

issue.setLabels(labelsSet)
issueManager.updateIssue(me, issue, EventDispatchOption.ISSUE_UPDATED, false)

}

 

Adding the code above to the Updated field server-side script does nothing

Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 24, 2018

Hi Edwin,

It is possible I am misunderstanding, but I don't think you would want to use a behaviour in this scenario. For adding labels to a parent epic, that doesn't seem like something that needs to be done instantaneously based on what's currently on the Edit form. Further, behaviours won't work at all if someone inline edits the Epic link field from the View screen.

I think you setting up a Script Listener is what you will want. For example, you can set up a listener that listens for the IssueLinkCreatedEvent. Whenever someone edits an issue to create a new Epic link, the listener will get triggered. The script you have above would then run to add the labels to the Epic.

Does that make sense?

Regards,

Josh

Edwin Ruiz
Contributor
October 24, 2018

Hey Josh,

Looks like that is a better route to go through. I will work on getting it to work on that event. It fires precisely when i want it to.

Edwin Ruiz
Contributor
October 24, 2018

Got it to work! :) For anyone trying to learn (Thanks Josh for the hint):

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent;
import com.atlassian.jira.issue.label.Label;
import com.atlassian.jira.exception.DataAccessException;
import com.atlassian.jira.ComponentManager;

def issueManager = ComponentAccessor.getIssueManager(); // get issue manager to deal with issues
def userManager = ComponentAccessor.getUserManager(); // get user manager to deal with users
def customManager = ComponentAccessor.getCustomFieldManager();
def me = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() // create application user (used later to update ticket)
def createLink = event as IssueLinkCreatedEvent;
MutableIssue epic = (MutableIssue) createLink.getIssueLink().getSourceObject(); // get current issue that triggered the event

String issueKey; // will be used to store issue key of epic
Set<Label> labelsSet = new HashSet<Label>();

if(epic != "null"){ // epic is not empty (shouldn't be since it is a issuelink created event)
def linkManager = ComponentAccessor.getIssueLinkManager(); // get linkmanager to get linked issues of epic
def listTickets = linkManager.getOutwardLinks(epic.getId()) // we are concerned about outward links from epic
def allDone = true

for (IssueLink link : listTickets) { // iterate through issue links
if (link.getIssueLinkType().getName() == "Epic-Story Link"){ // we only care about tickets in epic
if(link.getDestinationObject().getStatus().getName() != "Done"){ // only 1 tickets needs to not be done for the epic to not be done
allDone = false;
break;
}
}
}

labelsSet.addAll(epic.getLabels()); // add labels to hashset

if (allDone){
labelsSet.add(new Label(91185L, epic.getId(), "epic-done")) // create a label and add to set
}else{
for (Label label: labelsSet) { // iterate set
if (label.getLabel() == "epic-done") { // if "epic-done" label exists
labelsSet.remove(label); // remove from set
}
}

}
epic.setLabels(labelsSet) // set the label field for epic with the set
issueManager.updateIssue(me, epic, EventDispatchOption.ISSUE_UPDATED, false) // update issue (without this changes don't save)
}

 

Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 25, 2018

Hi Edwin,

Glad to hear you got it working. Nice work!

Regards,

Josh

Suggest an answer

Log in or Sign up to answer