Forums

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

How can I filter through lookupIssues with if statement

Vitali Fedarau
September 14, 2022

I need to create a report with Jira automation, that will combine tasks by epics, like that:

Epic 1:

Task 1

Task 2

Epic 2:

Task 3

Task 4

I have gon through A LOT of articles and made A LOT of testing, but the best possible result I see the usage of filtering through lookupIssues. I have used this article as basis for that: https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588

In my head, it should work in some way like this:

{{#lookupIssues}}
{{ #if({{equals(issue.epic.key,"EPIC-1"))}}}}

Epic 1 sumary
<{{url}}|{{key}} {{summary}}>
{{ /}}
{{/}}

 

{{#lookupIssues}}
{{ #if({{equals(issue.epic.key,"EPIC-2"))}}}}
Epic 2 summary
<{{url}}|{{key}} {{summary}}>
{{ /}}
{{/}}

So kinda filtering through epic key should allow to show only those tasks who are part of EPIC-1 or EPIC2. Unfortunately, that doesn't work at all.

Does anyone know what is the good way of doing this?

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Neta Elyakim
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.
July 18, 2018

You don't have an event for issue clone on Jira cloud, and even when you clone a ticket you can't know what was the original ticket because there is no link between them.

Brittany Wispell
Community Champion
July 18, 2018

Hi @Neta Elyakim

The creation of the link when you clone is optional. It is done by design of our ScriptRunner team. 

If you have any questions about it let me know! 

Neta Elyakim
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.
July 18, 2018

Hey@Brittany Wispell,

Thank you for informing me.

@Drew Nedderman

If you have a link between them you can try to use this script-

def getComments = get('/rest/api/2/issue/${issue.key}/comment')
.header('Content-Type', 'application/json')
.asObject(Map)

if (getComments.status == 200){
def comments = getComments.body.comments["body"]

logger.info("comments: "+comments)

if(!comments.isEmpty()){

def issuelinks = issue.fields["issuelinks"]
def inwardIssue = issuelinks["outwardIssue"] // or def inwardIssue = issuelinks["inwardIssue"] you need to check this

def cloneIssue
def requestBody
for(int i=0;i<inwardIssue.size();i++){
// check here the like type if is clone type
cloneIssue = inwardIssue[i]
}
if(cloneIssue != null){
for(int i=0;i<comments.size();i++){
def commentResp = post("/rest/api/2/issue/${cloneIssue.key}/comment")
.header('Content-Type', 'application/json')
.body([body: comments[i].toString()])
.asObject(Map)

assert commentResp.status == 201
}
}
}
}
0 votes
Brittany Wispell
Community Champion
February 15, 2018

Hey @Drew Nedderman

You could modify this code. It is for a parent subtask relation. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment

Issue subtask = event.issue
Comment comment = event.comment
def commentManager = ComponentAccessor.getCommentManager()

if (subtask.isSubTask() && comment) {
def parentIssue = subtask.getParentObject()
def commentToParent = commentManager.create(
parentIssue, //the parent issue to copy the comment
comment.getAuthorApplicationUser(), //the author of the subtask's comment
comment.getBody(), //the actual comment body
comment.getGroupLevel(), // is the group name to limit comment visibility to, this must be a valid group name.
comment.getRoleLevelId(), // is the id of the the ProjectRole to limit comment visibility to, this must reference a valid project role.
false) //if true then an event of type EventType.ISSUE_COMMENTED_ID will be dispatched and any notifications listening for that event will be triggered. If false no event will be dispatched.
log.info "Comment copied to parent issue ${parentIssue.getKey()}"
}

 

And here's a snippet of how you'd get the linked issues. 

def originIssue
issueLinkManager.getInwardLinks(issue.id)?.each {issueLink ->
issueLink.sourceId
Issue candidateIssue = issueManager.getIssueObject(issueLink.sourceId)
if(candidateIssue.projectObject.key.equals(cloneParentKey)){
originIssue = candidateIssue

 

I hope this helps get you started.  

Drew Nedderman
Contributor
February 15, 2018

Hi @Brittany Wispell, does the code that you provided work for cloud instances? When I past it into the console I get static type checking errors.

 

Unable to resolve class for these lines:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment

 Thank you for your assistance!

Brittany Wispell
Community Champion
July 18, 2018

Hey @Drew Nedderman

Try adding ; to the end of those lines.

TAGS
AUG Leaders

Atlassian Community Events