Forums

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

Scriprunner obtain project and status of all issue linked.

Sergio Palacio April 12, 2018

Hi everyone.

I'm trying to obtain the status and project key of linked issues to create a clone of the main issue but when I'm applying the log the project and status have false value and doesn't have de Project key and status.


following my code. 


import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)


def issuelinkPJ = issueLinkManager.getOutwardLinks(issue.id).any{it.destinationObject.getProjectObject().getKey()}
def ORstatus = issueLinkManager.getOutwardLinks(issue.id).any{it.destinationObject.getStatus().getName()}

if (!issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('is blocked By')) {
if (issuelinkPJ == 'OR' && ORstatus == 'Blocked'){
return true
}
}

 

2 answers

1 accepted

0 votes
Answer accepted
Sergio Palacio April 13, 2018

Ok I found a rustic way.
It is working.


for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
if (link.issueLinkType.name != "is blocked by") {
log.warn("LINK IS NOT - IS BLOCKED BY")
if (link.getSourceObject().getStatus().getName().contains("Blocked")){
log.warn("STATUS BLOCKED")
if(link.getSourceObject().getProjectObject().getKey().contains("OR")){
log.warn("PJ OR = OK")
}
else{
log.warn("IS NOT PJ OR")
}
}
else{
log.warn("STATUS NOT BLOCKED")
if(link.getSourceObject().getProjectObject().getKey().contains("OR")){
okflagfalse = 1
}
}
}
else {
log.warn("LINK == IS BLOCKED BY")
if(link.getSourceObject().getProjectObject().getKey().contains("OR")){
okflagfalse = 1
}
}
}
log.warn("STATUS=" + okflagfalse)
if (okflagfalse == 1) {
return false
}
if (okflagfalse == 0) {
return true
}
0 votes
Ivan Tovbin
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 Leaders.
April 12, 2018

Hi Sergio,

Your code is very confusing.

First off, 'any' closure returns a boolean value. Looking at your code both 'issuelinkPJ' and 'ORstatus' variables will have a 'false' value. Then you are trying to compare them, boolean values, with string values ('OR' and 'Blocked'). Naturally it simply doesn't work like this.

Secondly, this line is also wrong:

if (!issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('is blocked By'))

Assuming you want to check if that none of the links in your issue have the name 'is blocked By' then your code should be like this:

if (!issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType*.name.contains('is blocked By'))
Sergio Palacio April 13, 2018

I just resolved doing it.

Maybe my code is not the optimal but I resolved the problem.

import org.apache.log4j.Category
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager

def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)

IssueLinkManager linkMgr = ComponentAccessor.getIssueLinkManager()

for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
if (!issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('is blocked By')) {
if (link.getSourceObject().getStatus().getName().contains("Blocked")){
if(link.getSourceObject().getProjectObject().getKey().contains("OR")){
return true
}
else{
log.warn("message")
}
}
else{
log.warn("message")
}
}
else{
log.warn("message")
}
}



Sergio Palacio April 13, 2018

mmm I 'm having a logic problem. Because this code is for create only one issue cloned. But when I press the transition button again it is create another ticket. 


Sergio Palacio April 13, 2018

@Ivan Tovbin
Thanks for your help.



I need to know if any linked issue have "is Blocked by" relatioship and if the statuas is iqueal to blocked and if the project is equal OR.

 

Suggest an answer

Log in or Sign up to answer