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

AndreH May 5, 2016

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

0 votes
Ashraful Hasan [Adaptavist] May 6, 2016

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.

AndreH May 6, 2016

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

AndreH May 11, 2016

Hello,

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

Please help.

Ashraful Hasan [Adaptavist] May 11, 2016

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"  

AndreH May 12, 2016

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

 

Ashraful Hasan [Adaptavist] May 12, 2016

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.

AndreH May 13, 2016

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)

AndreH May 17, 2016

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?

Ashraful Hasan [Adaptavist] May 19, 2016

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.

  

AndreH May 23, 2016

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

AndreH May 31, 2016

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

0 votes
AndreH May 6, 2016

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

0 votes
Ashraful Hasan [Adaptavist] May 5, 2016

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.   

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events