Hi all,
I'm trying to figure out how to create a condition for the ScriptRunner "Send a custom email" post function.
The condition I need is that scriptrunner ONLY sends the email if an issue/request was within a previous status named "Revisions Needed".
Can anyone help me out here?
Thanks,
mike
Hi again @Peter-Dave Sheehan
For some reason, no matter how hard we tried we couldn't get your condition to work.
We ended up using the coding below after revisions:
import com.atlassian.jira.component.ComponentAccessor
def baseUrl = ComponentAccessor.applicationProperties.jiraBaseUrl
def link = """<a href=\"${baseUrl}/browse/${issue.key}\">${issue.key}</a>"""
config.ticketLink = link
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
//If the issue has been within the 'Revisions Needed' status - this email SHOULD not run.
!changeHistoryManager.getAllChangeItems(issue).find {
it.field == "status" &&
"Revisions Needed" in it.toValues.values()
}
Also, for reference - The positioning of the condition must be AFTER any configuration(s) within this section. If there are configurations after a condition, the script will automatically be defined as "true".
The code above does the following:
1) Grabs a hyperlinked ticket ID of the request the post function is firing within, and makes it available to be grabbed within the body of your email via "${config.ticketLink}"
2) Conditions the email to run if and ONLY if the request has NEVER been within the "Revisions Needed" status.
Just, checking...
IF the current issue was once before at any time in the status "Revisions Needed", then send the email during this postfunction/transition.
Correct?
This means that you need to look into the change history for the issue to see what previous status it's been in.
Something like this:
import com.atlassian.jira.component.ComponentAccessor
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def allPrioriStatues = changeHistoryManager.getChangeItemsForField(issue,'status').collect{[it.fromString, it.toString]}.flatten().unique()
if(!allPrioriStatues.contains('Revisions Needed')) return false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Peter! I'll try to implement this and see how it goes.
Thanks again,
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Peter-Dave Sheehan
We've run into an issue where we have both some configuration AND this condition within the "Condition and Configuration" top section of the "Send a custom Email" post function which makes the email not work.
Do we need to set this condition before we set any configurations? Our current configuration within this section pulls the ticket ID from the issue and makes it available within our email template / email body.
Thanks,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would suggest you put this before the rest of your configuration code. This way you can exit the condition with a false result before looking up the other issue details.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Peter-Dave Sheehan
I'll try to update that section and see if that does the trick.
For reference, let's say I'd want to send a separate email if and only if an issue was never in the "Revisions Needed" status. Would I only need to change the ending "false" to be "true" within the previously provided code block?
Thanks again for all the help,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, you need to change the condition that will cause the script and the function to abort. "return false" means "don't send the email".
So in this case, just remove the ! in the if block.
That will change it from
//change from
if(!allPrioriStatues.contains('Revisions Needed') return false
//to
if(!allPrioriStatues.contains('Revisions Needed') return false
In English:
before: if allPrioriStatues does NOT contain "Revisions Needed" then skip this email
after: if allPrioriStatues DOES contain "Revisions Needed" then skip this email
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.