Script Listeners - Send a custom email. Problem sending email.

I have created a Script Listener that will send a Custom Email.

The Condition is suppose to check all existing sub-task have the following:

1.) Has a label of Transfer
2.) Checks that the sub-task is set to the Closed status

Upon the last sub-task being set to Closed, the email needs to be sent.

There can be multiple sub-tasks and anyone of them can be set to Closed. Only then should the email be sent.

This use to work with ScriptRunner version: 3.1.4, however it doesn't work in Version: 4.1.3.10.

There is no email sent.

Here is the Condition:

issue.labels.any{it.label=='Transfer'} &&
(issue.isSubTask() && issue.parentObject.subTaskObjects.every {it.getResolutionObject()})

JIRA Version 6.4.13
Adaptavist ScriptRunner for JIRA Version: 4.1.3.10

Here are the screen shots for the Listener with the Parent Issue with Sub-tasks

Three.bmp

One.bmp

Two.bmp

3 answers

Hi - Can you please remove the condition and check email sends as expected or not? It it works fine then perhaps you can add few if blocks to break the condition into small sub-conditions to pinpoint the problem.   

Condition Completely Removed - Success on email

Only - ( issue.labels.any{it.label=='Transfer'} ) - Success on email

Only - ((issue.isSubTask() && issue.parentObject.subTaskObjects.every {it.getResolutionObject()})) - FAILED on email

Hi - For at least one of the issue the resolution is not set [number 3 sub task state is assigned]. You can check available resolution from "Administration -> Issues -> Resolutions" section. I have restructured your code a bit so that you can see for which issue the resolution is not set.

if(issue.labels.any { it.label == 'Transfer'} && issue.subTask){
    def allsubTasks = issue.parentObject.subTaskObjects
    allsubTasks.each {
        Resolution resolution = it.getResolutionObject()
        if(resolution) {
            log.debug "issue: ${it.summary} resolution: $resolution.name"
        }
        else
        {
            log.warn "no resolution for ${it.summary}"
        }
    }
}

Otherwise I don't see any issue.

I only have the default Resolutions:

Resolved (Default)
Unresolved

I updated the Condition code and it is giving me the following error -

startup failed: Script28.groovy: 4: unable to resolve class Resolution @ line 4, column 20. Resolution resolution = it.getResolutionObject() ^ 1 error

Error1.png

Hello,

Is there any update to my last post with the error?

Please help.

hi - Instead of "Resolution resolution = it.getResolutionObject()" you can use "def resolution = it.getResolutionObject()" to avoid the error message. Or you can also use import statement "import com.atlassian.jira.issue.resolution.Resolution"  

Changing the item to "def resolution = it.getResolutionObject()" got rid of the error.

However, now on every time a sub-task is Closed and email is sent out. This shouldn't be the results. It should only send out an email when the Last sub-task is closed. i.e. the last sub-task of 17 sub-tasks.

Here is the log file when I close a sub-task:

 

2016-05-12 08:24:23,423 ajp-bio-8009-exec-12 WARN jcuser1 504x61x1 erm49v 1.1.1.1 /browse/HD-128264 [jira.plugins.customfield.TemplatesCFType] Issue template: step8: 08:24:23.423
2016-05-12 08:24:23,424 ajp-bio-8009-exec-12 WARN jcuser1 504x61x1 erm49v 1.1.1.1 /browse/HD-128264 [jira.plugins.customfield.TemplatesCFType] Issue template: end getParameters: 08:24:23.424
2016-05-12 08:24:23,700 ajp-bio-8009-exec-12 WARN jcuser1 504x61x1 erm49v 1.1.1.1 /browse/HD-128264 [jira.plugins.customfield.TemplatesCFType] Issue template: step8: 08:24:23.700
2016-05-12 08:24:23,700 ajp-bio-8009-exec-12 WARN jcuser1 504x61x1 erm49v 1.1.1.1 /browse/HD-128264 [jira.plugins.customfield.TemplatesCFType] Issue template: end getParameters: 08:24:23.700
2016-05-12 08:24:28,355 ajp-bio-8009-exec-17 WARN jcuser1 504x103x3 erm49v 1.1.1.1 /secure/AjaxIssueEditAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: step8: 08:24:28.355
2016-05-12 08:24:28,356 ajp-bio-8009-exec-17 WARN jcuser1 504x103x3 erm49v 1.1.1.1 /secure/AjaxIssueEditAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: end getParameters: 08:24:28.356
2016-05-12 08:24:59,439 ajp-bio-8009-exec-15 INFO jcuser1 504x252x1 1bxa5d3 1.1.1.1 /rest/jira-mail-plugin/1.0/outgoingMail/config [jira.mail.settings.MailSetting] Mail setting 'jira.mail.send.disabled' has been set to 'false'
2016-05-12 08:25:18,178 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for Helpdesk ready sub-tasks
2016-05-12 08:25:18,188 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for Business Objects New Employee/Temp Setup (form)
2016-05-12 08:25:18,188 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for Citrix Remote Access New Employee/Temp Setup (form)
2016-05-12 08:25:18,188 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for DC New Employee/Temp Setup (form)
2016-05-12 08:25:18,188 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for SSO Account New Employee/Temp Setup (form)
2016-05-12 08:25:18,188 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for eCel New Employee/Temp Setup (form)
2016-05-12 08:25:18,189 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for SmartAd New Employee/Temp Setup (form)
2016-05-12 08:25:18,189 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for PremiumW New Employee Provisioning (form)
2016-05-12 08:25:18,189 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for Add Phone Book Record
2016-05-12 08:25:18,189 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for OTL Setup (IT contractor)
2016-05-12 08:25:18,189 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for New IT Employee/ IT Contractor Setup (IT only)
2016-05-12 08:25:18,189 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for Jira New Employee/Temp Setup
2016-05-12 08:25:18,190 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for Subversion New Employee/Temp Setup
2016-05-12 08:25:18,190 ajp-bio-8009-exec-5 WARN jcuser1 505x286x1 erm49v 1.1.1.1 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] no resolution for Open FW ports (IT ONLY)
2016-05-12 08:25:21,020 ajp-bio-8009-exec-5 WARN jcuser1 505x288x1 erm49v 1.1.1.1 /secure/AjaxIssueAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: step8: 08:25:21.020
2016-05-12 08:25:21,020 ajp-bio-8009-exec-5 WARN jcuser1 505x288x1 erm49v 1.1.1.1 /secure/AjaxIssueAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: end getParameters: 08:25:21.020
2016-05-12 08:25:21,465 ajp-bio-8009-exec-5 WARN jcuser1 505x288x1 erm49v 1.1.1.1 /secure/AjaxIssueAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: step8: 08:25:21.465
2016-05-12 08:25:21,465 ajp-bio-8009-exec-5 WARN jcuser1 505x288x1 erm49v 1.1.1.1 /secure/AjaxIssueAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: end getParameters: 08:25:21.465
2016-05-12 08:25:21,511 ajp-bio-8009-exec-5 WARN jcuser1 505x288x1 erm49v 1.1.1.1 /secure/AjaxIssueAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: step8: 08:25:21.511
2016-05-12 08:25:21,511 ajp-bio-8009-exec-5 WARN jcuser1 505x288x1 erm49v 1.1.1.1 /secure/AjaxIssueAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: end getParameters: 08:25:21.511
2016-05-12 08:25:23,290 ajp-bio-8009-exec-5 WARN jcuser1 505x289x1 erm49v 1.1.1.1 /secure/AjaxIssueEditAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: step8: 08:25:23.290
2016-05-12 08:25:23,290 ajp-bio-8009-exec-5 WARN jcuser1 505x289x1 erm49v 1.1.1.1 /secure/AjaxIssueEditAction!default.jspa [jira.plugins.customfield.TemplatesCFType] Issue template: end getParameters: 08:25:23.290

 

Hi - The original code checks whether all issues have resolution or not. It does not check issue status. If you  want to set a condition true upon last issue is closed then you should have "

issue.parentObject.subTaskObjects.every { it.status.name == "Closed"}

as you can set a resolution without closing the issue.

Hello,

I changed the code to:

issue.labels.any{it.label=='Transfer'} &&
(issue.isSubTask() && issue.parentObject.subTaskObjects.every {it.getResolutionObject()})

The emails is sent when the it is an Atlassian Standard sub-task (works)

However, when I am using a Custom created sub-task, there is no email sent (fails)

Is there an option to set the debug for this?

I am looking at the 2 Sub-tasks (1 is ootb and 1 is a custom). The custom sub-task has some added Post Functions at the Close Issue Transition. I'm thinking this is where the issue is occurring.

However when I set debug for (com.onresolve.jira.groovy). I don't get any data that is useful.

Is there another setting?

Hi - Please follow the link, a screenshot is provided to set the log level:

https://scriptrunner.adaptavist.com/latest/jira/getting-help.html

If you have already configured log level then you should be able to see messages. Also check "atlassian-jira.log" file for errors. In case you don't see any error, that  means there is no error in the script but logically the condition is invalid. In that case you have to break the logic into small parts and log them to see their value.

  

I have set both items. Script Console and Logging and Profile.

I am still getting no debug information for this plugin, shouldn't I see something other than null? and no logs?

 

SetLog.png

It seems as though the issue is occurring with the Post Function Step 4.

If I remove this Post Function, the email is sent.

My question is, why is it failing with Post function Step 4?

Shouldn't it sent the email based on Post Function 10? Fire Closed Issue Event?

See screen shot

Issue-Post-Function.png

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 Thursday 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...

86 views 0 5
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