Hi, I am fairly new to Jira and very new to Groovy scripts, so my apologies in advance if what I am having trouble with is basic. I have tried everything I can think of or find from the internet, but I'm not quite able to get it working.
I have Issues A, B and C. Issue C is blocked by Issues A and B and is flagged as it cannot be started until both Issues A and B are resolved (have a resolution of 'Done'). In reality there may be more issues blocking C, but for the purposes of explanation I'll stick with just A and B.
I am trying to create a Post Function whereby when an issue that blocks C is transitioned to 'Done', Issue C's flag is cleared as long as all other issues that also block C have a resolution of 'Done'.
To do this, I am using the JMWE Post Function Clear field(s) of related issues, clearing the 'flagged' field of each issue that is blocked by the current issue, using the condition (in Post Function 2):
Condition in text in case it's hard to see in the image:
issue.get("issuelinks","blocks")?.every{issue.get("issuelinks","is blocked by")?.every{issue.getAsString("resolution")=="Done"}}
Steps in words of what I'm trying to do:
1. Find all issues which are linked (blocked by) the the current issue.
2. For all of those issues, find all of the issues that link (block) them.
3. Check the statuses of every issue found in step 2. If all have a resolution of 'Done', then
return true and run the Post Function. Otherwise, return false and don't run the Post Function.
Here is where my lack of Groovy knowledge may well shine. When I run this, the condition returns 'true' if either issue A or B has a resolution of 'Done', whereas I want it to only happen if they both have a resolution of 'Done', hence the use of 'every'.
If anyone can point me in the right direction as to how to get this working I would be very grateful!
Don't hesitate to tell me I have no idea what I'm doing and to try a completely different way , as I probably haven't thought of it. The only limitation I have is that the only app I have access to is JMWE.
Many thanks for reading.
Hi Caroline,
Welcome to the community.
You didn't specify what wasn't working in your case. Your script returns a collection of issue links. The collection of issue links is considered truthy and hence the condition passes. Your condition should be simplified to:
relatedIssue.getLinkedIssues("is blocked by").every{it.getAsString("resolution") == "Done"}
Regards,
Radhika
Hi Radhika,
Many thanks for replying. I tried the code above, but it doesn't do what I need I'm sorry to say. I am new at Groovy.
The code you provided seems to check that all issues blocking the current issue have a resolution of 'Done'? I need to go up the other way - to issues that are being blocked by the current issue.
So using the issues A, B and C example - where issue C is blocked by both A and B - when transitioning issue A to 'Done' I need it to:
1. Find the issues that are blocked by A (which in this example should find just issue C)
2. For issue C, find all the issues that block it (which should be A and B)
3. Check that both A and B have a resolution of 'Done'
4. If they both do, remove the flag from issue C. If either of them don't, don't run the Post Function.
The code that I have come up with (in original post) returns a Boolean - true or false.
It works fine except that it's returning a true if either issue A or issue B have a resolution of 'Done', and only returns a false if neither of them do.
I need it to return a true only if all of the blocking issues (ie A AND B) have resolutions of 'Done', and otherwise a false.
Sorry if I didn't explain it very well in my original post!
It's the same problem as described in another question here: https://community.atlassian.com/t5/Jira-questions/Unflag-an-issue-if-all-the-blocking-issues-are-resolved/qaq-p/1263253 but I need to implement the condition using JMWE rather than Scriptrunner or Jira Workflow Toolbox.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Caroline,
Let me summarize what I understand.
Link type from C -> A and B - "is blocked by"
Link type from A -> C or B -> C - "blocks"
You have placed the "Clear field of related issues" post-function on the "Done" transition of the workflow issue A and C follow. When you trigger the transition "Done" on A or C, you want the Flagged field to be cleared on C only when A and C are in "Done" statys. To achieve this using JMWE:
relatedIssue?.getLinkedIssues("is blocked by").every{it.status.name == "Done"}
Your configuration will look something like this:
relatedIssue here points to the issue C automatically. So you need to find issues linked to C through "is blocked by" link type and then check that they are in the status "Done".
Why your script failed: You were accessing the issue links and not the linked issue objects. And hence you cannot get the resolution. Try this and let me know.
Regards,
Radhika
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Radhika,
Thank you so much for taking the time to help me with this! And thank you for explaining why my code wasn't working, it has helped me understand a lot more about Groovy.
The code you provided works perfectly, and I am very grateful!
Kind regards,
Caroline
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your welcome.
Regards,
Radhika
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.