Unable to auto resolve issue if all linked ticket closed

Martin LALONDE January 21, 2021

Hello everyone,

My objective is to be able to automaticaly transistion ticket from the JSD (Yes I'm still on a previous version) when all linked ticket in other projects in my instance are closed.

This is used for user account creation and require many teams to have their own tickets within their project. Hence the reason I cannot use an automation within JSD.

I've been looking into scriptrunner to help me out but I'm not a dev but have basic knowledge on coding language.

I'm trying to use fast-track on the transition "Mark as transfer", which is setting the status to "Transferred" (Pending), on the post function that should validate that all linktype issue on are "relates to"  closed to do action "Mark as resolved" from my workflow when issue is set to transferred.

This is the code I have entered in the condition box found on https://scriptrunner.adaptavist.com/5.2.2/jira/recipes/workflow/conditions/all-dependent-issues-resolved.html

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def linkType = ["relates to"]

def linkMgr = ComponentAccessor.getIssueLinkManager()
for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
if (linkType.contains(link.issueLinkType.name)) {
if (! link.sourceObject.resolutionId) {
passesCondition = false
}
}

}

I have found someone else with a similar issue with this script here but even trying his modification to the script I still have an error within the coding box that mention 

 [Static type checking] - The variable [passesCondition] is undeclared at @ line 10, column 713 

I've also added in additinal issue actions box the following code from the snippets hoping it would fix it but nothing is happening.

import com.atlassian.jira.component.ComponentAccessor

def constantsManager = ComponentAccessor.getConstantsManager()
def resolution = constantsManager.resolutions.findByName("Done")

issueInputParameters.setResolutionId(resolution.id)

 When publishing my workflow and testing my ticket which have tickets linked as relates to to the status "Mark as transfer" nothing is happening.

I have check the post functions and it say no failures but I have no log either.

Jira: 8.5.2
Scriptrunner: 6.0.0-p5 

 

If you have something else to propose then this script I am open for suggestion.

3 comments

Comment

Log in or Sign up to comment
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 21, 2021

Hi @Martin LALONDE , I do not know if I understand it correctly but I can see one possible problem. You are using "getInwardLinks" method which returns only issues which are set as source of the links for your issue.

We need to find out whether it is problem or not and we can fix it to be more save in second step.

So just try to replace "getInwardLinks" with "getOutwardLinks" and let me know.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 22, 2021

@Martin LALONDE by the way, static error is not problem... this property "passesCondition" is scriptrunner's condition property, so it is declared but groovy compilator just can't know it :)

Martin LALONDE January 22, 2021

@Martin Bayer _MoroSystems_ s_r_o__  and @Ivica Vančina thanks for your prompt reply on this issue. 

I've made the changes suggested with the condition box and now it looks like this.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def passesCondition = true
def linkType = ["relates to"]

def linkMgr = ComponentAccessor.getIssueLinkManager()
for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
if (linkType.contains(link.issueLinkType.name)) {
if (! link.sourceObject.resolutionId) {
passesCondition = false
}
}

}

And it didn't change the status or transition to Done of the parent ticket when all linked relates to ticket dans closed.

So I've also seen within one of the articles here in Scriptrunner that when doing a workflow transition if there a screen attached to this it might block the action.

issueInputParameters.skipScreenCheck()

So I added the issueInputParameters line into the additional issue actions

import com.atlassian.jira.component.ComponentAccessor

def constantsManager = ComponentAccessor.getConstantsManager()
def resolution = constantsManager.resolutions.findByName("Done")

issueInputParameters.setResolutionId(resolution.id)
issueInputParameters.skipScreenCheck()

I saved and publish my workflow change but no luck and no failures displayed.

Workflow display.png

Thank again for your help on this issue.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 22, 2021

OK @Martin LALONDE let's start from the scratch. I will try to describe how I understand your issue and situation.

  1. you have service desk issue SD-1
  2. there are multiple issues created to solve SD-1 like
    1. HR-1 for HR department
    2. IT-1 for IT department
    3. SEC-1 for security department
  3. you need to move SD-1 issue to Done when all the linked issues (HR-1, IT-1, SEC-1) are done

For this situation, you need to configure postfunction in HR, IT, SEC workflow on its last transition (to Done status) and configuration must contain invocation of SD workflow's transition "Mark as done".

Do I understand it right? Is your configuration similar? Can you post screenshots or zip them and post the archive here?

Martin LALONDE January 22, 2021

@Martin Bayer _MoroSystems_ s_r_o__  Yes this is exact, I can have between 1 and 5 issues created in different projects link to the main ticket in SD.

Sorry if I didn't explain my situation like this since I didn't think it would have an impact.

If adding a post function on each done transition within the impacted project, this need to validate that current link issue are all in done before closing the SD issue.

Here an example of how my issue is generated.

In the SD portal user fill in a form to specify what the new hire requires. Then when service request is created a post function create issues in each project depending on selected fields (Element Copy & sync add-on) and this work perfectly.

jira - SD ticket with link ticket.png

There is 3 project impacted IT, SIHR and TRAIN. The IT tickets are separated by a section (PC, phone and network) but are same issue type.

I have not finalized my workflow status this is a new process we are putting in place and I'm currently using a development instance to test this.

Thanks again and have a nice weekend,

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 23, 2021

Hi @Martin LALONDE thank you for the information. What I miss is how do you try to invoke transition on "root" service desk issue? Fast-track issue transition an issue provides function which invoke transition on issue itself but you need to invoke it on the linked issue.

I think you need something like https://beecom-products.atlassian.net/wiki/spaces/JSU/pages/25680446/Linked+Transition or to implement scripted postfunction.

But try to describe this part to me and we'll see.

Martin LALONDE January 25, 2021

Hello @Martin Bayer _MoroSystems_ s_r_o__ 

Ok, here are some screenshot of my workflow setting and how I've setup the fast-track Scriptrunner function.

This is the screenshot of my workflow transition on mark as transfered.

Workflow - transition transferred.png

This is what I've setup for the fast-track script transistion.

Post function - Fast track 1.png

Post function - Fast track 2.png

 

When I've search for selecting the transistion script fast-track this is what I've selected.

Selection post function.png

Thanks again,

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2021

I can see two problems in your configuration (if I understand it correctly). I tried to draw something:

community.png

  1. as you can see, you have to invoke "Mark as resolved" from the "related" issue but on "source" issue -> SUP-1
  2. you are invoking Mark as resolved from transition Mark as transfered, but configuration of Fast track transition an issue and its condition does not cause the "parent" transition (Mark as transfered) is not completed when condition fails. The result is that Mark as transfered is completed and Mark as resolved is not completed (when condition fails).

I think you need to have transition Mark as resolved set as so called "self transition" (From: any status, To: itself, Condition or validators are implemented in this transition) and if you do not want to use another App, you have to write a script which will invoke transition Mark as resolved and will not allow you to perform transition if its conditions fail.

I can see an example of how to make transition on the issue in groovy here: https://community.atlassian.com/t5/Marketplace-Apps-Integrations/ScriptRunner-how-to-automatically-transition-an-Epic-to/qaq-p/628780

  • method transitIssue
Like Martin LALONDE likes this
Martin LALONDE January 28, 2021

@Martin Bayer _MoroSystems_ s_r_o__ Indeed presented this way it make sense that each linked issue try to transist the SUP ticket from Open to done if all linked issue are already closed.

I have looked into the post mentionned and it would need to do the same action but this script is looking into the Epic and Subtask that are linked together.

I'll try to work around that script logic to build my own from it, do you think you can help out it would be very appreciated.

Thanks,

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 28, 2021

Hi @Martin LALONDE sure, I can HELP you, but I would not be ok to write it on my own as this forum's intention is to help, not to provide full support :).

If you accept this rule we can definitelly discuss progress on your script :) Try to prepare something so we can work on it.

Martin LALONDE January 29, 2021

@Martin Bayer _MoroSystems_ s_r_o__ I fully understand this and wasn't my objective to have someone else do the work for me your knowledge and approve are very helpful that what I appreciate from this community. I want to learn to get better myself with scripting in groovy language.

I have found a few resources online on Groovy and I guess I should have started with this before trying just to take premade script and hope it would work on the first try.  

Are the following ressources are good?

https://igorpopov.io/2014/11/24/rocking-with-jira-script-runner/

https://www.guru99.com/groovy-tutorial.html 

And I've also found a list of components class within Jira

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/component/ComponentAccessor.html 

I will work on the it and keep you updated.

Thanks again for your time helping me out.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 29, 2021

Hi @Martin LALONDE thank you for your attitude!!! :) To be honest, I used to be a Java developer, so I do not know good resources for learning groovy. But what works for me is starting coding and searching for the information which I just need.

There are also snippets on Adaptavist's bitbucket https://bitbucket.org/Adaptavist/workspace/snippets/ (just be aware, you need to learn server version which is mentioned in the title of the script most of the time).

And you will definitelly need ComponentAccessor to load needed Jira API services. 

You can share link to some shared document where you will build your script -> it will be more readable. After we have it done, we can past the final code here.

Ivica Vančina January 22, 2021

Well you are getting error because your variable (passesCondition) is not defined, or in other words ScriptRunner doesn't know where did you get this from.

So you need to define it like this: def passesCondition = true 

Then after that you can use it.

Ivica Vančina January 28, 2021

Hi,

Your script and setup is fine except your script checks if  your linke issues are closed, but on the end of your CONDITION part you need to "return" something.

So to make your script work you need to put passesCondition == true  on the end of your script and everything will work fine.

 

Have a nice day.

Martin LALONDE January 28, 2021

@Ivica Vančina If I add that at the end of my condition script is close my main ticket and ignore if linked ticket are open or closed.

I try placing it on different line but doesn't do anything.

Maybe I don't get it right, like mentionned I'm not a developper but I'm trying to learn how to use groovy script for scriptrunner.

Thanks,

Ivica Vančina January 29, 2021

@Martin LALONDE 

Here try this script it should work:

 

def passesCondition
def linkType = ["Relates"]


def LinkManager = ComponentAccessor.issueLinkManager
LinkManager.getOutwardLinks(issue.id).each { IssueLink issueLink ->
if (issueLink.issueLinkType.name in linkType) {
def resolutions = issueLink.destinationObject.resolutionId
if(resolutions == null){
passesCondition = false
}else{
passesCondition = true
}
}
}

passesCondition == true
Ivica Vančina January 29, 2021

@Martin LALONDE give me feedback when you try this script....

Martin LALONDE January 29, 2021

Hello @Ivica Vančina Thanks for trying to get this script working.

I've replaced the current script with the one you suggested but came back with error on the editor on line 6 "unable to resolve class IssueLink".

I will be going another direction following discussion with @Martin Bayer _MoroSystems_ s_r_o__ since the goal is to automate the closing of issue on the JSM side when linked issue are all closed.

Ivica Vančina January 29, 2021

@Martin LALONDE Hi, this script works fine. Problem was that I didn't paste import classes on my last post. This script checks every single linked issue with "relates to" link that is on your main issue and if one of them don't have resolution, the main issue wont transitioned.

If you need any other help or advice, you are free to ask.

Please provide me a feedback if this is fine now.

 

Here, this is full script:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink


def passesCondition
def linkType = ["Relates"]


def LinkManager = ComponentAccessor.issueLinkManager
LinkManager.getOutwardLinks(issue.id).each { IssueLink issueLink ->
if (issueLink.issueLinkType.name in linkType) {
def resolutions = issueLink.destinationObject.resolutionId
if(resolutions == null){
passesCondition = false
}else{
passesCondition = true
}
}
}
passesCondition == true

 

Ivica Vančina January 29, 2021

@Martin LALONDE Hi script works fine I didn't paste import classes on my last post. This script checks every single linked issue with "relates to" link type and then if every linked issue is closed, then you get true condition... And you your case your main issue transition on right Status.

 

If you need any other advice and help, don't hesitate to ask.

Please write me a feedback after you try it again. 

 

Here, this is full script:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink


def passesCondition
def linkType = ["Relates"]


def LinkManager = ComponentAccessor.issueLinkManager
LinkManager.getOutwardLinks(issue.id).each { IssueLink issueLink ->
if (issueLink.issueLinkType.name in linkType) {
def resolutions = issueLink.destinationObject.resolutionId
if(resolutions == null){
passesCondition = false
}else{
passesCondition = true
}
}
}
log.info("Every linked issue is closed -> " + passesCondition)
passesCondition == true

 

Ivica Vančina January 29, 2021

@Martin LALONDE Hi, script works fine I didn't paste import classes on my last post. This script checks every single linked issue with "relates to" link type and then if every linked issue is closed, then you get true condition... And you your case your main issue transition on right Status.

 

If you need any other advice and help, don't hesitate to ask.

Please write me a feedback after you try it again. 

 

Here, this is full script:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink


def passesCondition
def linkType = ["Relates"]


def LinkManager = ComponentAccessor.issueLinkManager
LinkManager.getOutwardLinks(issue.id).each { IssueLink issueLink ->
if (issueLink.issueLinkType.name in linkType) {
def resolutions = issueLink.destinationObject.resolutionId
if(resolutions == null){
passesCondition = false
}else{
passesCondition = true
}
}
}
log.info("Every linked issue is closed -> " + passesCondition)
passesCondition == true

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 29, 2021

Hi @Ivica Vančina , please, review the thread above. @Martin LALONDE probably does not have problem with condition but with invocation of service management issue transitions.

TAGS
AUG Leaders

Atlassian Community Events