Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,616
Community Members
 
Community Events
176
Community Groups

Update multi select field based from email body




Hi  

Can someone can help me on how to update multi select field based from the email body using scriptrunner email handler?

Jira data center

Vetrical field is multi select field

 

Email body



final String body = """This is a test body

Vertical: [ "option1","option2"]

Description: sample description

"""

 

Appreciate your help on this

1 answer

0 votes

This is a script which is generally useless because it's a composite example - it shows you how to set a value of every type of standard custom field.

You should be able to extract the bits that refer to multi-selects quite easily

https://library.adaptavist.com/entity/update-the-value-of-custom-fields-through-the-script-console

Hi @Nic Brough -Adaptavist- 

 

I've already tried that one but I'm not sure how to pass the variable to select option.

 

 

Here's my Scriptrunner mail handler script

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.service.util.ServiceUtils
import com.atlassian.jira.service.util.handler.MessageUserProcessor
import com.atlassian.mail.MailUtils
import com.atlassian.jira.user.ApplicationUser
//This requires the name of the user that will trigger the Mail Handler
final def username = 'testuser'

//This requires the Project's Key that will be used for the Mail Handler
final def projectKey = 'EA'

//This requires the name of the Issue Type that will be used
final def issueTypeName = 'Story'


def userManager = ComponentAccessor.userManager
def projectManager = ComponentAccessor.projectManager
def issueManager = ComponentAccessor.issueManager
def issueFactory = ComponentAccessor.issueFactory
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

def user = userManager.getUserByName(username)
//def issueReporter = messageUserProcessor.getAuthorFromSender(message) ?: user
ApplicationUser reporter = messageUserProcessor.getAuthorFromSender(message) ?: user
def project = projectManager.getProjectObjByKey(projectKey)
def subject = message.subject as String
def messageBody = MailUtils.getBody(message)


def cfVertical = customFieldManager.getCustomFieldObjectsByName('Vertical').first()

def issue = ServiceUtils.findIssueObjectInString(subject) as MutableIssue

if (issue) {
return
}

def issueObject = issueFactory.issue
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setIssueTypeId(project.issueTypes.find { it.name == issueTypeName }.id)
issueObject.setReporter(reporter)

//vertical
def regex = /(?<=\[\[)([^\[\]]*)(?=\]\])/
def emailMatch = (MailUtils.getBody(message) =~ regex).findAll().first() as List
def VerticalEmail = emailMatch.first() as String

//issueObject.setDescription(MailUtils.getBody(message))
issueObject.setDescription(VerticalEmail)
issue = messageHandlerContext.createIssue(user, issueObject) as MutableIssue

 

def fieldConfig = cfVertical.getRelevantConfig(issue)
def options = optionsManager.getOptions(fieldConfig)
def option = options.findAll { it.value in [VerticalEmail] }

issue.setCustomFieldValue(cfVertical, option)

issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH,false)

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events