Workflow transition - Scriptrunner post function conditional execution help

Josh Clearihan April 7, 2018

Hi experts,

We recently made workflow changes, stupidly, without backing up the previous workflow, this has broken our employee 'Offboarding' process when creating tickets, I'm hoping someone has some suggestions.

I'm having issues with the conditional execution of the Create issues and subtasks post function.

Our goal is to automatically create 6 linked issues with specific description. This functionality works fine, however, to prevent the double creation of linked issues if ticket flows through the same transition more than once, we have added the below condition. 

%{Customer Request Type Name} = "Offboarding" and %{Number of linked issues} = 0 

I have attached a photo of the post function and an example Offboarding ticket.

ScreenHunter_39 Apr. 08 15.07.jpgScreenHunter_38 Apr. 08 14.59.jpg

1 answer

0 votes
Roland Holban (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 Leaders.
April 10, 2018

Hey I think this is the condition you are looking for. The condition will return true if the issue type is "Offboarding" and the issue has 0 inward links and 0 outward links.

import com.atlassian.jira.component.ComponentAccessor

def linkManager = ComponentAccessor.issueLinkManager

def hasInwardLinks = linkManager.getInwardLinks(issue.id).empty
def hasOutwardLinks = linkManager.getOutwardLinks(issue.id).empty

return issue.issueType.name == "Offboarding" && !hasInwardLinks && !hasOutwardLinks
Josh Clearihan April 20, 2018

Thanks Roland! Sorry for the delay it has been a busy couple of weeks!

I attempted your scripting condition within the conditional execution of the post function but an error was thrown, this could be due to syntax not being boolean?

With this assumption I tried adding the script to an actual condition in the transition, the syntax returned no errors but did not function as expected i.e. issue links were created when parent ticket contained linked issues.

Would I be correct in assuming you script is not compatible with boolean expression? Would you know a boolean script to acheive the same outcome or have any other suggestions?

 

ScreenHunter_55 Apr. 20 17.51.jpg

Roland Holban (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 Leaders.
April 20, 2018

Are you using JIRA cloud or JIRA server?

The error screenshot you sent is not familiar to me.

Roland Holban (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 Leaders.
April 20, 2018

Unfortunately, if you are using JIRA Cloud, I wont be able to help you. JIRA Cloud is almost completely different from JIRA Server and ScriptRunner scripts are not interchangeable.

With that said the code I originally sent you had a logic error in it :P

hasInwardLinks and hasOutwardLinks would ent up true whenever the issue didnt have links and vice versa.

Here is a fix. You can try to implement something similar.

import com.atlassian.jira.component.ComponentAccessor

def linkManager = ComponentAccessor.issueLinkManager

def hasInwardLinks = !linkManager.getInwardLinks(issue.id).empty
def hasOutwardLinks = !linkManager.getOutwardLinks(issue.id).empty

return issue.issueType.name == "Offboarding" && !hasInwardLinks && !hasOutwardLinks

 

 

 

Josh Clearihan April 20, 2018

We are using Jira server and ScriptRunner, thanks for picking up the error I will retest shortly.

I still dont know where exactly I should be using this script?

1. In the conditional execution of the Create issues and subtasks post function.

2. A condition step within the transition 

3. Custom script within a post function step

Josh Clearihan April 24, 2018

I tried your modification in multiple condition options in the transition and still no dice.

It would help if I know exactly where within the transition this condition needs to be applied.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events