Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set default reporter for non-jira user in scriptrunner mail handler

Vikrant Yadav
Community Champion
April 20, 2022

Hello Friends,

Need one help in setting default reporter for non-jira users in scriptrunner mail handler and select list field (Enviornment) default value is not working. Kindly help me in correcting my script :- 

 

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

def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.getProjectManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)

def detail_description = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Detailed Description")

def envionment = getFieldByName("Environment")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(envionment.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionToSelect = options.find { it.value == "Production" }

def subject = message.getSubject()
def body = MailUtils.getBody(message)
def issue = ServiceUtils.findIssueObjectInString(subject)

ApplicationUser user = userManager.getUserByName("vikrant-yadav2")
ApplicationUser reporter = messageUserProcessor.getAuthorFromSender(message) ?: user
def project = projectManager.getProjectObjByKey("HBBOP")

def issueObject = issueFactory.getIssue()
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setCustomFieldValue(detail_description, body)
issueObject.setCustomFieldValue(envionment.setFormValue(optionToSelect.optionId))
issueObject.setCustomFieldValue()
issueObject.setIssueTypeId(project.issueTypes.find { it.name == "Bug" }.id)
issueObject.setReporter(reporter)

messageHandlerContext.createIssue(user, issueObject)

Thanks

V.Y

2 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
April 23, 2022

Hi @Vikrant Yadav

This may be doable, but I need to clarify: is this for a Service Desk project or a Software project?

If it is for the former, it may be doable if the sender's email address is already added to the Service Desk Customers.

However, if it is for the latter, I'm not so sure that it's doable.

Thank you and Kind regards,

Ram

Vikrant Yadav
Community Champion
April 23, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_  This is for JIRA Software. I am trying to setup default repoter for non-jira users.

Thanks

V.Y 

0 votes
Vikrant Yadav
Community Champion
April 23, 2022

@PD Sheehan  kindly suggest mate

thanks

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2022

Sorry Vikrant, I have no experience with the scriptrunner mail handler.

Suggest an answer

Log in or Sign up to answer