Maybe someone can help me creating the correct expression for a conditional execution of a post function?
My workflow is
To 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 Impeded
C. 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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add these imports as well ,
import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.IssueManager
let me know the remaining errors, I will try with a hands-on and update you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again
Thanks for your patience on this
Still not working.
When dragging a sub task from "impeded" to In Progress" flags are NOT cleared on sub-task and flag is NOT clear on Parent (even if no other subtask are
In the inline script box the scrip now produce "error markers" as follows, though now i am able to actually add the script
image2016-6-15 11:10:42.png
image2016-6-15 11:13:36.png
image2016-6-15 11:13:58.png
image2016-6-15 11:14:55.png
image2016-6-15 11:15:26.png
image2016-6-15 11:15:56.png
image2016-6-15 11:16:21.png
image2016-6-15 11:16:43.png
After saving/adding the script, and execute it by moving a card from "impeded" to "in progress"
Following information were registered in the log...
ime (on server): Wed Jun 15 2016 10:58:49 GMT+0200 (Romance Daylight Time) The following log information was produced by this execution. Use statements like:log.info("...") to record logging information. 2016-06-15 10:58:49,264 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2016-06-15 10:58:49,264 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SUP-11, actionId: 51, file: <inline script> groovy.lang.MissingPropertyException: No such property: ComponentAccessor for class: Script12 at Script12.run(Script12.groovy:14)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh!! I will try it with a hands-on soon and come back with the results.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hold on!! This script is for our requirement during the subtask's transition from In Progress to Impeded status. This has to be added in the post function available in the In Progress -> Impeded transition step. Make sure the script is placed just below this post function 'Set issue status to the linked status of the destination workflow step.'
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 String currentStatus = issue.getStatus().get("name").toString() 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); }
For the post function of Impeded to In Progress, I will share the script separately. Now please test this script for the In Progress -> Impeded transition from the subtask ALONE !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have now added the script to the transition In "Progress --> Impeded" . Still the same errors as mentioned in my previous comment.... But even if it worked, it would really not solve my problem...
I think I need to clarify my original intensions further as it might not have been all that clear...
I was able to succesfully create the following Post funtions:
Post function on Transtion: In Progress --> Impeded:
- The Flagged of the issue will be set to Impediment. (Update Issue Custom Field Function)
- The value(s) of field Flagged will be copied to the issue's parent's field (replacing existing values). (Copy Field Value to Parent Function)
This allows me to verify the following when a subtaks is moved from in progress to Impeded:
I was also able to succesfully create the following Post functions
Post function for transition: Impeded --> In Progress
- The contents of the field Flagged will be purged. (Clear Field Value Function)
- The value(s) of field Flagged will be copied to the issue's parent's field (replacing existing values).(Copy Field Value to Parent Function)
This Allow me to verify the following when a subtask is moved from Impeded to in Progress:
The challenging part is that I only want to remove the flag from the parent issues, if the parent issue has no sub-tasks marked as Impeded/flagged.
Therefore my issue lies only on the transition from Impeded --> In progress. I want to replace the second postfunction with one like this:
In other word, i need help to write the condition only, as all other postfunction works for me...
Does this helps you in any way?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes. Thanks a lot for your patience as well.
Alas, lets give a try again with your approach. Lets focus on the first scenario alone on transition step Impeded --> In Progress . Lets add a condition in your Copy Field Value to Parent Function as given below.
import com.atlassian.jira.component.ComponentAccessor; import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.Issue import com.atlassian.jira.config.SubTaskManager boolean result = true SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager() Collection subTasks = issue.getParentObject().getSubTaskObjects() def count = 0 if (subTaskManager.subTasksEnabled && !subTasks.empty) { subTasks.each { String status = it.getStatus().getName().toString() //log.error(status) if(status.equals("In Progress")) { count = count+1 //log.error(count) } } } if(count != 1) { result = false } return result
Make sure the script is placed just below this post function 'Set issue status to the linked status of the destination workflow step.'
Is it working?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well no succes... In my desperation of finding out why this doesn't work i tried different random stuff, including delelting a lot of code. During that process i discovered something really weird...
I found that the following script obviously returns true and therefore executing the post function, since it is only imports and a "return true"
import com.atlassian.jira.component.ComponentAccessor; import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.Issue import com.atlassian.jira.config.SubTaskManager //boolean result = true //SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager() //Collection subTasks = issue.getParentObject().getSubTaskObjects() return true
However, for some reason, the script below doesn't execute the post function, so apperantly this doesn't return true.
import com.atlassian.jira.component.ComponentAccessor; import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.Issue import com.atlassian.jira.config.SubTaskManager //boolean result = true SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager() Collection subTasks = issue.getParentObject().getSubTaskObjects() return true
I may be overlooking something, as my knowledge in scripting is very limited, but it seems like adding those two lines, for some reason "overwrites" the return true...??
I have no clue if this can help the debugging process...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The last script of mine had worked for me. Can you please share a screenshot of your post function used and all postfunction's order in that transition?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
image2016-6-16 15:23:29.png
Here you go... Your script has been added as condition to the function marked with X
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1) How are you having a IN PROGRESS status on both the sides? IN PROGRESS -> IN PROGRESS doesn't seems valid.
2) Hope you have created the workflow from the diagramatic view. Here, these post functions will be shared while other transitions like TO DO -> IN PROGRESS as well.
However, if my script works fine here, the result will be,
Also share a screenshot of your Copy field value to Parent post function you have configured.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1) My workflow allows all statuses to transition into all statusses. It looks like this:
image2016-6-16 20:5:30.png
I believe this should be valid, as it is a standard this to "allow all statusses to transition to this status".
2) Yes... You are right.
Here is the screen shot of the Postfunction configuration of the Copy Field Value to Parent function:
image2016-6-16 20:10:30.png
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This means that your code is working fine for that scenario. Lets check the other scenario from In Progress -> Impeded state. Please set the post functions in this order.
Value of the field Flagged should be copied to the issue's parent field with this script condition.
import com.atlassian.jira.component.ComponentAccessor; import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.Issue import com.atlassian.jira.config.SubTaskManager boolean result = true SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager() Collection subTasks = issue.getParentObject().getSubTaskObjects() def count = 0 if (subTaskManager.subTasksEnabled && !subTasks.empty) { subTasks.each { String status = it.getStatus().getName().toString() //log.error(status) if(status.equals("Impeded")) { count = count+1 //log.error(count) } } } if(count != 1) { result = false } return result
and so on.
Test 1:
Check this post function when no other subtasks are in Impeded state.
Expected result : Script returns true and hence Flagged is set as 'Impediment' in parent as well.
Test 2:
Check this post function when other subtasks are in Impeded state.
Expected result : Script returns false and post function fails. (Flagged wont be copied).
Please try it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have to go abroad for a few weeks. I'll look more into this and get back your you when I am back. Thanks for your patience :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alright.. Happy journey!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.