Need help with groovy condition?

Warren McInnes
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.
April 22, 2014

I'm trying to write a condition that fires an event with the groovy script runner?

I need to fire an event when the due date has been updated or changed?

Is this possible?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Boris Georgiev _Appfire_
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.
April 22, 2014

Have you looked at that - https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Firesaneventwhenconditionistrue

Why do you want to fire event in a condition and not post-function?

I think the "Fires an event when condition is true" post-function will work for you with the following condition

issue.dueDate != originalIssue.dueDate

Warren McInnes
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.
April 22, 2014

My idea was to use the "Fires an event when condition is true" Script Listener?

I think "issue.dueDate != originalIssue.dueDate" is correct, however i think the syntax may be incorrect? I don't think "originalIssue" exists?

Boris Georgiev _Appfire_
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.
April 22, 2014

What makes you think it does not exist ?

Warren McInnes
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.
April 22, 2014

I just tried to test it in the Builtin Script Runner - Condition Tester

And i got the following result:

The result evaluated to false

Tip: If you're not getting the right result add an assert statement to the questionable line. See docs for examples (click question mark icon above).

It it is correct I will try and run it?

I copied issue Updated event? (Called it: issue Due Date Changed) When it fires the "issue Due Date Changed" event will it show whether the due date was changed? Or must this be specified somewhere?

Boris Georgiev _Appfire_
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.
April 22, 2014

I'm not sure the condition tester will work in that case as there is no real change in the due date.

Regarding the event it will show nothing just this event will be fired. What happens as a result from the event depends on how the notification scheme is configured and if there are any registered listeners for this event.

Warren McInnes
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.
April 22, 2014

Alright, so you suggest I rather do a post-function? Or could the script listener and events do the trick?

I basically just want 2 nofitfy the project lead of due dates changes/updates?

Boris Georgiev _Appfire_
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.
April 22, 2014

Create a custom event and then configure the post-function to fire this event when the due date is changed (as described above).

Then configure the notification scheme of the project to notifiy the project lead when that event is fired

https://confluence.atlassian.com/display/JIRA/Adding+a+custom+event

If you want to customize the email sent when this event is fired see this article

https://docs.servicerocket.com/display/ATLASSIAN/How+to+create+a+custom+event+in+JIRA

Warren McInnes
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.
April 22, 2014

Great, I'll give it a try. Thanks for all your help.

JamieA
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.
April 22, 2014

Listener is probably the right way to go, but originalIssue is not available for listener - an example for listeners with a change of priority would be:

issue.priority?.name == 'Major' && changeItems.any {
	it.get('field')=='priority'
}

so you would just need to use the due date field name: duedate

JamieA
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.
April 22, 2014

And Boris is right, you can't really test either of these in the condition tester, as there is no event.

Warren McInnes
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.
April 22, 2014

HI Jamie,

Thanks for your imput. I used the listener instead of the post-function, but I did use originalIssue and it seems to have worked. So I'm quite pleased.

Thanks guys for all the advice. It Works!!!!

JamieA
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.
April 22, 2014

oh yeah, it's there, my bad.

Warren McInnes
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.
April 23, 2014

No worries :) Is there anywhere documentation to learn this Language/syntax?

Like some kind of tutorial?

E.g. issue.dueDate != originalIssue.dueDate

E.g.issue.priority?.name == 'Major'&& changeItems.any {

it.get('field')=='priority'
}
JamieA
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.
April 23, 2014

After reading https://jamieechlin.atlassian.net/wiki/display/GRV/?

Unfort the useful docn is scattered amongst multiple pages. Then you could do some groovy tutorials to understand GDK methods like "any".

Reading https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Simplescriptedconditionand doing some experimentation will get you quite far. If you know java you have a big leg up.

But short answer, you just need to do the legwork. I think it's worth it, but I'm biased.

TAGS
AUG Leaders

Atlassian Community Events