Use Groovy Script Runner to notify a team only once when a value is set on an issue

Hi:

What's the most elegant way to accomplish the following in GSR:

  1. Keep an eye on the "Needs QA" field, which is a "yes" or "no" choice.
  2. When the "Needs QA" field gets set to "yes", send an email to QA saying "hey, you guys need to look at this issue."
  3. Don't send another notification email to QA about that issue UNLESS "Needs QA" gets set to "no", and then back to "yes" again.

I have a half-assed solution in place using GSR, but I have no clue how to accomplish the "send only one mail per each time "Needs QA" gets set to "Yes"" part.

As a result, QA is getting email for every issue update after "Needs QA" gets set to "yes", because my solution sees every issue update as an update in which "Needs QA" is set to "yes". I want to have the script somehow recognize "oh, I've already sent mail once, I don't need to do it again".

3 answers

1 accepted

2 votes

For listeners, you can AND your check of the custom field with:

changeItems.any {it.get('field')=='Needs QA'}"

ie, so the value is Yes, AND the value was changed in this transition.

Or move it to a workflow function as Henning says, which will be easier for you and might be more clearer for the users.

You know I love you, but I think Henning's idea is the right one for this application.

However, I still have a stupid question for you!

When formatting the email to be sent, how do I:

  • Properly insert a line break
  • Identify the person who made the last comment

I am currently doing this godawful thing, which provides a working line break but terrifies me:

<p>
<% if (componentManager.getCommentManager().getComments(issue)) out << "The most recent comment on the issue was: <p><i>" << componentManager.getCommentManager().getComments(issue).last()?.body %>
</i>
<p>

I agree Henning's answer is the right way to go ;-)

If using html format you need to use <p> or <br>... if using text format you can just use a newline - "\n".

You may get mismatched tags the way you have it now but shouldn't cause major problems... otherwise just add << "</i></p>" after the .body bit.

2 votes
Henning Tietgens Community Champion May 06, 2013

Hi,

what about removing the Needs QA field from the edit screen and make it only editable through a global transition (cyling back to the current status)?

Than you have two possible solutions:

  1. For this transition you can use a new event and for this event you can put QA into the corresponding notification scheme. In this way, QA only gets a notification if the value of this field is changed.
  2. You can trigger an email through Script Runner post function only if the value of the Needs QA field is set to "Yes".

Henning

Awesome, Henning. This is exactly the way we want to go.

0 vote
Mizan Community Champion May 06, 2013

You will need to check the history of the issue , If the value of "Needs QA" is changed from No to yes then an custom event can be fired , on this event email will be sent to the required group from notification scheme .

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Apr 19, 2018 in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

366 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you