Does Post Function, conditional execution, support groovy script?

Manajit Rath September 7, 2015

I have created a parent transition post function, and then selected "Only if condition is true".

Initially, I wrote the code:

if ("a" == "a") {

return true;

}

Thus, every time, I executed the transition, the post function triggered the parent transition, which shows that the if statement executed and returned true.

 

However, the moment I try to put in some logic, rather even a single statement, the parent transition doesnot get triggered, which I believe is because the code is either not getting executed or has an error. The code which is not working is given below:

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.web.action.issue.CreateSubTaskIssue

import com.atlassian.jira.web.action.issue.CreateSubTaskIssueDetails

import com.atlassian.jira.user.util.UserManager

import com.atlassian.jira.config.SubTaskManager

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.watchers.WatcherManager

 

def MutableIssue currentIssue = issue

 

if ("a" == "a") {

return true;

}

 

Want to know, can we write a script in the condition of the post function. If yes, whats the issue with the above script?

 

Regards,

Manajit.

1 answer

0 votes
Taha Khanzada
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.
September 7, 2015

Hi Manajit,

Yes, you can write script in the Workflow condition, post function and Validator.

What you are trying to do here def MutableIssue currentIssue = issue ?

Taha

 

 

Manajit Rath September 10, 2015

I am extremely sorry for the delay in the reply. Just to give you a background, what I essentially want to do is, on the transition of a subtask type "Development Subtask" to done state, check for the status of all the "Development Subtask"s of the parent story. Only if all the "Development Subtasks" are in Done state, then I want to execute a particular transition on the parent story. The pseudocode is: 1. Get the parent story of current issue 2. Get all development type subtasks of the parent issue 3. Loop through all the development subtasks. 4. Check the status of the development subtask, if it is not done then return false 5. After the completion of the loop. Return true. However, as I am new to jira groovy and am not sure of how to debug, I started writing one statement at a time and testing it with every change. The below code without "def MutableIssue currentIssue = issue" worked fine for me and the transition on the parent story was executed as I am returning a true always. import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.web.action.issue.CreateSubTaskIssue import com.atlassian.jira.web.action.issue.CreateSubTaskIssueDetails import com.atlassian.jira.user.util.UserManager import com.atlassian.jira.config.SubTaskManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.watchers.WatcherManager if ("a" == "a") { return true; } However, the moment I introduced the statement "def MutableIssue currentIssue = issue" in the code as is given in my original question, it stopped working. I don't know what is going wrong and also don't have a clue as to how to debug. Do let me know, if you can help me understand how to debug or give me a snippet which I can then take ahead. Manajit.

Suggest an answer

Log in or Sign up to answer