Maybe someone can help me creating the correct expression for a conditional execution of a post function?
My workflow isTo Do --> In Progress --> Impeded --> Done
I have made following post functions on sub-tasks transitions TO "Impeded"A. Set Flagged to "impediment" (on sub-task)B. Copy value of Flagged to parent issue replacing existing values
Post functions on sub-task transitions FROM ImpededC. Clear Flagged (on sub-task)D. Copy value of Flagged to parent issue replacing existing values
All seems to be working fine however:I want a conditional postfunction, that will copy value of "Flagged" to parent issue ONLY if parent issues has no flagged subtasks (Alternatively: has no subtatsk with status "impeded")
I have no experience in groove expression Can anyone help?
/Jacob
Hope this works. Please let me know the results.
import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.comments.CommentManager; import com.opensymphony.workflow.WorkflowContext; import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.util.ImportUtils import com.atlassian.jira.config.SubTaskManager; import com.atlassian.jira.util.JiraUtils; IssueManager issueManager = ComponentAccessor.getIssueManager() CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() CustomField myCustomfield = customFieldManager.getCustomFieldObjectByName("Flagged") myCustomfield.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(myCustomfield), "impediment"),changeHolder); SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager(); Collection subTasks = issue.getParentObject().getSubTaskObjects() def count = 0 if (subTaskManager.subTasksEnabled && !subTasks.empty) { subTasks.each { String status = it.getStatus().get("name").toString() if(status.equals("impeded")) { count = count++ } } } if(count != 1) { myCustomfield.updateValue(null, issue.getParentObject(), new ModifiedValue(issue.getParentObject().getCustomFieldValue(myCustomfield), "impediment"),changeHolder); }
Thanks Mahesh S.It didn't quite work as expected.I have used the "Copy Field Value to Parent Function" and inserted you script in the COnditional Execution field - see below
I guess the script is supposed to "return true" if parent has no subtask with status impeded? WorkflowFunctionCondition.PNG
You are in Copy Field Value to Parent function now. You can move out and use my first script directly in a scripted post function.
However, please use this script, if you need to use the script as a condition for this post function itself.
import com.atlassian.jira.ComponentManager import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.util.ImportUtils import com.atlassian.jira.config.SubTaskManager import com.atlassian.jira.util.JiraUtils IssueManager issueManager = ComponentAccessor.getIssueManager() CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() /*CustomField myCustomfield = customFieldManager.getCustomFieldObjectByName("Flagged") myCustomfield.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(myCustomfield), "impediment"),changeHolder);*/ //hope you did this in a separate post function above this. SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager(); Collection subTasks = issue.getParentObject().getSubTaskObjects() def count = 0 def boolean = false if (subTaskManager.subTasksEnabled && !subTasks.empty) { subTasks.each { String status = it.getStatus().get("name").toString() if(status.equals("impeded")) { count = count++ } } } if(count == 1) { boolean = true } return boolean
Please let me know the results.
Hi Mahesh
I have tried using your second script as a condition for the post fuction it self (Yes i added the "Clear flag on current item" as a seperate post fuction... No positive result.
Since this is hard to debug, i tried adding your first script as a script postfunction (removing the clear flag and copy value to parent post function)...
Following errors occured:
The script could not be compiled: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script4.groovy: 12: unable to resolve class IssueManager @ line 12, column 14. IssueManager issueManager = ComponentAccessor.getIssueManager() ^ Script4.groovy: 15: unable to resolve class ModifiedValue @ line 15, column 40. myCustomfield.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(myCustomfield), "impediment"),changeHolder); ^ Script4.groovy: 34: unable to resolve class ModifiedValue @ line 34, column 58. ull, issue.getParentObject(), new Modifi ^ 3 errors
It looks like you're new here. Sign in or register to get started.