Hi Team , There is one requirement from my side where I am stuck -> Via Incoming Mail handler , I want whenever the mail is sent to particular mail id the ticket would be created but in the project workflow the component/s is set as mandatory in validator , so whenever the mail is sent the incoming mail handler would be scripted in order to set the component/s by default as "test" since component is a system field as well an array I am not getting the function to set it.
Here is my code, could you please help me to set the Reporter who is sending the mail and assignee a particular mail and the component as "TEST"
CODE :
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.service.util.handler.MessageUserProcessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.MutableIssue
import java.util.regex.Pattern;
import java.util.regex.Matcher
import com.atlassian.jira.workflow.TransitionOptions
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.getProjectManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def project = projectManager.getProjectObjByKey("TESTJIRA")
ApplicationUser user = userManager.getUserByName("abcd")
def issueObject = issueFactory.getIssue()
issueObject.setSummary("Test TPO")
issueObject.setDescription("Test Description")
issueObject.setIssueTypeId(project.issueTypes.find { it.name == "Service Request" }.id)
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Components")
issueObject.setCustomFieldValue(customField,"TEST")
messageHandlerContext.createIssue(user, issueObject)
Hi @Shrikant Pandurang Mandlik
Component is a system field and not a custom field.
You can handle it using something similar to:
def myComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.project,'MYCOMP')
issue.setComponent([myComponent])
Hi @Tom Lister ,
After using this as well it is giving me NullPointerException and WorkflowException can you please correct the below code :
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.service.util.handler.MessageUserProcessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.MutableIssue
import java.util.regex.Pattern;
import java.util.regex.Matcher
import com.atlassian.jira.workflow.TransitionOptions
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.getProjectManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def project = projectManager.getProjectObjByKey("TESTJIRA")
def myComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),"TEST")
ApplicationUser user = userManager.getUserByName("abcd")
def issueObject = issueFactory.getIssue()
issueObject.setSummary("Test TPO")
issueObject.setDescription("Test Description")
issueObject.setIssueTypeId(project.issueTypes.find { it.name == "Service Request" }.id)
issueObject.setComponent([myComponent])
messageHandlerContext.createIssue(user, issueObject)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Shrikant Pandurang Mandlik
Does the component TEST exist? If not the call to find it will return null.
You can test for null and either create a new one on skip the setComponent option
it’s a good idea to put log statements when debugging new code.
Also worth checking that the user is being returned and not null
I’ll be offline now until after the weekend
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.
Hi @Shrikant Pandurang Mandlik Similar post , kindly check this link :-
First create the issue, then try to update the issue fields. Reporter you can set before creating an issue.
Thanks
V.Y
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vikrant Yadav ,
I want to set field before creating issue as I could've used post function for that. But I want to distinguish between the issues created by mail and created via Jira.
So can you please suggest me correction for below code as it is giving me NullPointerException and WorkflowException can you please correct the below code :
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.service.util.handler.MessageUserProcessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.MutableIssue
import java.util.regex.Pattern;
import java.util.regex.Matcher
import com.atlassian.jira.workflow.TransitionOptions
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.getProjectManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def project = projectManager.getProjectObjByKey("TESTJIRA")
def myComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),"TEST")
ApplicationUser user = userManager.getUserByName("abcd")
def issueObject = issueFactory.getIssue()
issueObject.setSummary("Test TPO")
issueObject.setDescription("Test Description")
issueObject.setIssueTypeId(project.issueTypes.find { it.name == "Service Request" }.id)
issueObject.setComponent([myComponent])
messageHandlerContext.createIssue(user, issueObject)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.