Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

how to update system and custom fields from a scriptrunner mail handler

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

1 answer

1 accepted

1 vote
Answer accepted

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

@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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

94 views 0 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you