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

I want to set cascade field in scriptrunner email handler

achoudhary June 24, 2022

I am using this script to update additional fields while using scriptrunner email handler

but every value i am fetching except cascade field value.

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.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.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue

def issueObject = issueFactory.getIssue();

def client = customFieldManager5.getCustomFieldObjectByName("Casecade field")
def config5 = client.getRelevantConfig(issueObject) //this is the configuration that contains all your options
def options5 = optionsManager5.getOptions(config5)
def clientOption = options5.find{it.value == "Option"}
def subject = message.getSubject() as String
ApplicationUser user = userManager.getUserByName("admin")
ApplicationUser reporter = userManager.getUserByName("admin")
def project = projectManager.getProjectObjByKey("SD")


issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(MailUtils.getBody(message))
issueObject.setIssueTypeId(project.issueTypes.find { it.name == "Incident" }.id)
issueObject.setReporter(reporter)
issueObject.setCustomFieldValue(client, [null:clientOption])
messageHandlerContext.createIssue(user, issueObject)

 

Please help me on this one

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 25, 2022

Try to run issueObject.setProjectObject and issueObject.setIssueTypeId BEFORE you call getRelevantConfig(issueObject).

At the moment, when you get the relevant config, jira will not know which context to retrieve since the issue object you are passing doesn't have a project or issue type yet.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.MailUtils

//get the managers
def userManager = ComponentAccessor.userManager
def issueFactory =ComponentAccessor.issueFactory
def customFieldManger = ComponentAccessor.customFieldManager
def projectManager = ComponentAccessor.projectManager
def optionsManager = ComponentAccessor.optionsManager

//get some generic information
def user = userManager.getUserByName("admin")
def reporter = userManager.getUserByName("admin")
def project = projectManager.getProjectObjByKey("SD")
def issueType = project.issueTypes.find { it.name == "Incident" }
def clientCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Casecade field")[0]

//create the issue with basic info and message data
def issueObject = issueFactory.issue
issueObject.projectObject = project
issueObject.issueTypeId = issueType.id
issueObject.summary = message.subject
issueObject.description = MailUtils.getBody(message)
issueObject.reporter = reporter

//retreive issue context specific data
def clientConfig = clientCf.getRelevantConfig(issueObject)
def clientOptions = optionsManager.getOptions(clientConfig)
def clientOption = clientOptions.find{it.value == "Option"}

//apply context-sensitive data to issue
issueObject.setCustomFieldValue(clientCf, [null:clientOption])

messageHandlerContext.createIssue(user, issueObject)
TAGS
AUG Leaders

Atlassian Community Events