Trying to define a Condition in a Post-Function where I perform an Action based on a Condition.
The Condition is to look at the issue type and see if it equals a certain string value. Example below:
issue.issueType.name == "New Feature"
Is the syntax above correct? Does issue.issueType.name store the issue type?
In general, where does one go to fine out the class name and class state (variables) so one can write accurate Conditions in a Post-Function?
Yes it is correct (because getIssueType returns a GenericValue which implements Map, and you can get values by calling the key as a property in groovy), although it might be better to say:
issue.issueTypeObject.name == "New Feature"
> In general, where does one go to fine out the class name and class state (variables) so one can write accurate Conditions in a Post-Function
So there are two things you need to do this, 1) to know what variables you can use (ie are in the script binding), and 2) what types they are so you can work out what methods to call on them.
You can get 1) , and 2) actually, from here: https://studio.plugins.atlassian.com/wiki/display/GRV/Built-In+Scripts#Built-InScripts-TechnicalStuffforAdvancedUsers , or looking at the source code.
So for instance you know now that *issue* is a MutableIssue, so you look at the javadoc at http://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/MutableIssue.html.
Now you find you can call getIssueTypeObject() on it, and in groovy thing.issueTypeObject is just shorthand for the same.
And finally if you go to Admin -> Script Runner -> Built-in Scripts -> Condition Tester you can test the condition on various different issues, which is much easier than publishing a workflow. In your case above you would have got a MissingMethodException (or similar).
Really finally, if you set up the source in a good ide like intellij idea, you never need bother with the javadoc: https://studio.plugins.atlassian.com/wiki/display/GRV/Script+Runner#ScriptRunner-DebuggingandCodingwithIDEA
I read thru the instructions in the link and wondered 'how does this allow me to debug remotely?'. Maybe I am missing something but does it not say to download and install the source code locally (ok, no problem)? I have not used Intellij IDEA to do remote debugging. If it's just a matter of following the instructions on that link, I'll give it a shot. The step 'Assure you can run JIRA properly before continuing' also is confusing to me. How do I do that on my PC with 4Gb of memory (is that enough memory)?
I appreciate all your feedback btw -- very kind of you to assist.
4gb is plenty. You don't need the source code to use those instructions, it's mainly to give people intellisense. You can attach the javadoc as well then you don't need to browse it on the web. Having the source code is helpful if you want to step in to the jira classes but it's not necessary for writing a plugin.
Debugging remotely is the same as for any java app... just specify the name of the remote host.
Hi, for developing in JIRA it is better edit startup_bundled_jre.bat to run JIRA in debug mode.
Just add parameters
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9095
to set JAVA_OPTS=-server %JAVA_OPTS%
and connect to remote host on port 9095
I am not trying to develop a plugin, btw, but thanks for that input (I may do so in the future and its good to know).
I have installed Groovy and GroovyRunner and a post function (to Fast-track transition an issue) does not appear to be working. So I wanted to step through the code to see 'why' this problem exists.
Should this syntax also work for condition statements on post functions?
I've used the exact syntax above to apply a condition to a Transition Parent Issue post-function, but it doesn't fire. The post function works when I set no condition; it also works if I set a basic condition that will always return true ( like 1 == 1 ).
Do I need to be doing something like calling a library or something (I figured that one line would be enough in the context of "this" issue).
N.B. this is on JIRA 6.4.12 and ScriptRunner 188.8.131.52
Even though the question is over five years old yes it should still work.
If not try adding an assertion in the previewer: https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_power_assertions
What is your actual condition?
Thanks for getting back to me Jamie,
I know it's old, but it looks like exactly what I need, and I took a punt that you'd still reply pretty quickly!
I'll take a look at it with a power assertion. In the meantime, the thing I'm trying to do is this:
I'm applying a transition parent issue post function to a subtask's workflow. I only want the parent to transition when the subtask in question has a particular issue type.
So, in the post function (on the subtask's workflow) I've entered a condition line to test that the subtask's issuetype is a "Design Task" so:
Ah, I think I've figured something out! It looks to me like the post function for Transition Parent issue isn't one supplied by Scriptrunner. I disabled Scriptrunner in our non-production platform and the post function is still available to me!
I'd just assumed that it was because it was asking for a Groovy expression in the condition field.
The code you gave me works perfectly in an actual Scriptrunner post function (tested it in the Custom email one) but the one I'm having trouble with returns a NoSuchElementException in the logs.
I'm guessing I'll probably need to add in some import statement or other to get the right component accessor. Clearly this post function isn't as well written as your ones!
Thanks for your time!
OK, I've managed to sort it now, in case you're interested.
The post function is supplied by JIRA Misc Workflow Extensions, and it looks like it's set up to access a limited set of functions: issue, issueObject, or parentIssue.
After digging around I ended up with:
issue.get("issuetype").name == "Design Task"
Thanks again for your input Jamie
Any chance you have a solution for how to get actual issue status?
I have tried a lot of options and non was working for me:
issue.get("status").name == "Open"
issue.getSimpleStatus().getName() == "Open"
issue.get("status").getName() == "Open"
underlyingIssue.getStatus().getName() == "Open"
issue.getStatus().getName() == "Open"
issue.getStatusObject().getName() == "Open"
I just gave this a try (after finding the answer on another forum ) and it works for me:
I also tested it for the use case that I personally would apply it to: checking the status of the parent issue, which would be:
That works for me too. Incidentally, if you're having trouble getting the issue status for issue.get("status") in a transition post-function, maybe it's about the status of the issue at the point the post-function runs?
issue.get("status").getName() worked for me when I'd evaluated it against the status that the issue was moving from, rather than the one in moves to.
Does that help at all?
thank you for your input. I was following the same article you mentioned but without success. My use case is:
I have been googling a lot and removing transition to itself seems to be unsolved issue, i thought it could be solved with this condition but it does not work as I assumed.
Ah, I see; yeah, that wouldn't make much sense on a post function!
I've used "All" Transitions from time to time and I came up with the same problem. Personally I solved it by using the "Value Field" condition offered by Suite Utilities for Jira. If you've got the plugin, how the condition works is pretty much self explanatory: you just set "Status" as the field you're checking.
If you don't have Suite Utilities for Jira, definitely check it out; there's lots of useful things in it.
Hope that helps.
Finally, this forum works .
We have Suite plugin so I have tried proposed solution and it works fine. It takes more time than I would like to spent on this task (considering JIRA prices - creating field, seting it on transitions and than manually validate each transition) but finally its done.
Hi everyone! My name is Jenny, a Product Manager at Atlassian. After launching Team @mentions in Confluence, we heard a lot of positive feedback from customers that they love how easy it is to @men...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events