Hi...I am trying to write a scriptrunner incoming mail handler so when an email is received these three things must happen:
- Add a comment to the jira issue with the body of the email (I was able to do so!)
- Update Description field with the body of the email (does not work)
- Increased by 1 an integer custom field named "Total Replies Received" (dont know how to do it)
I am following the examples in the scriptunner documenation https://scriptrunner.adaptavist.com/latest/jira/mail-handler.html,
in the exanple Find Existing Issue, doing something like issue.setDescription ("variable with the body of the email here") does not work
May anybody assist?
Thank you
Hi Tomas,
I created this script below and is working from my side. Please give a try.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.service.util.ServiceUtils
import com.atlassian.jira.service.util.handler.MessageUserProcessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.mail.MailUtils
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.getProjectManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def subject = message.getSubject() as String
def issue = ServiceUtils.findIssueObjectInString(subject)
if (issue) {
log.warn "==========================SR Incoming Mail issue exists"
log.warn "issue: $issue"
ApplicationUser user = userManager.getUserByName("admin")
def issueManager = ComponentAccessor.issueManager
MutableIssue issueObject = issueManager.getIssueObject(issue.key)
issueObject.setDescription("this is an example")
//Custom Field code here
issueManager.updateIssue(user,issueObject,EventDispatchOption.ISSUE_UPDATED,false)
log.warn "==========================SR Incoming mail Ended"
}
{code}
To update a custom field value, you can append the code in the script before "*issueManager.updateIssue()*" API:
{code:java}
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Custom Field")
issueObject.setCustomFieldValue(customField,"numbers")
Thank you.
Kind regards,
John Chin
Hi John...it worked like a charm! This line definitely did the trick:
issueManager.updateIssue(user,issueObject,EventDispatchOption.ISSUE_UPDATED,false)
You guys always rock! Thank you so much
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@John Chin I am trying a similar one, however, I need to update the custom field single select drop down after an email is sent out in the escalation service. Is this possible? I was able to send email but cannot update the single select custom field. Can you pleasse help?
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.