how to add a user only to those tickets that were created from the mail "mypost@gmail.com" ? I think to do it through POST-function , but I only have part of the code
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def watcher = ["username1","username2"]
watcher.each{userName->
def user=ComponentAccessor. userManager.getUserByName(userName)
watcherManager.startWatching(user, issue)
}
Hi @Alex
For your requirement, it would be better to handle this in the Mail Handler.
Below is a sample code for your reference:-
import com.adaptavist.hapi.jira.projects.Projects
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
//This requires the name of the user that will trigger the Mail Handler
final def username = 'admin'
//This requires the Project's Key that will be used for the Mail Handler
final def projectKey = 'MOCK'
//This requires the name of the Issue Type that will be used
final def issueTypeName = 'Bug'
def userManager = ComponentAccessor.userManager
def issueManager = ComponentAccessor.issueManager
def issueFactory = ComponentAccessor.issueFactory
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def user = userManager.getUserByName(username)
def issueReporter = messageUserProcessor.getAuthorFromSender(message) ?: user
def project = Projects.getByKey(projectKey)
def subject = message.subject as String
def from = message.from as String
def messageBody = MailUtils.getBody(message)
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(issueReporter)
issue = messageHandlerContext.createIssue(user, issueObject) as MutableIssue
if (from == 'mypost@gmail.com') {
issue.addWatcher()
}
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH,false)
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to modify it accordingly.
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.