Appreciating any help/guidance:
In a Jira Service Management project (Data Center), we have a third party app that creates tickets in this project via email. The Jira ticket Reporter is setting a generical email from this app and then, we need to change it manually to the right user(email included in the Jira ticket Description when created).
The right output would be to set the right Reporter automatically when the ticket is created(instead of the generical app email).
The idea is to use Scriptrunner, with a Post function in the Create transition to set the right user with this kind of script:
import com.atlassian.jira.component.ComponentAccessor // the username of the reporter
final String userName = "user_name" def user = ComponentAccessor.userManager.getUserByName(userName) issue.setReporter(user)
But first, I need to get the email from the Description field, using a regular expression. I use reggex101 to figure it out:
https://regex101.com/r/7dYFI3/1
"[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}"i
This regular expression is getting the email, and now I don´t know how to assign it to the username variable.
Since I don´t have the expertise to develop this script with scriptrunner, would be very appreciate it if you guys could help me to achieve this :)
Any other workaround is welcome. Cheers
Hi @Martin Benavides set the reporterUser to the value from your regex
def reporterUser= "Value of Regex"
then set up your issueObject
def issueObject = issueFactory.issue
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(MailUtils.getBody(message))
issueObject.setIssueTypeId(project.issueTypes.find { it.name == defaultIssueType }.id)
issueObject.setReporter(reporterUser)
try {
(messageHandlerContext as MessageHandlerContext).createIssue(user, issueObject)
} catch (CreateException e) {
log.error('Error creating issue: ', e)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your help @Craig Nodwell and apologize for my lack of experience (working on it).
I just set the value of the regex but scriptrunner is not accepting it:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script2557.groovy: 1: unexpected char: '\' @ line 1, column 27. def reporterUser= "[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I thought you were further into your script.
First off you need to get that email out of the Description Field.
Then you need to do a replaceAll on the string with your regex.
I'll have a further look for you tomorrow.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wish I had it :(
The Regex provided above, will take the email out of a paragraph, but yeah, I don´t know how to develop the script to use this regex, take the email out of the description and then set it in the reporter.
Thank you for your help, I really appreciate it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'll need a few hours maybe even tomorrow I have work to do this afternoon standing up a new delivery pipeline tool stack.
Here's some links if you want to get started on your own.
Scriptrunner Library
Scriptrunner Tutorials
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.
@Martin Benavides here's another one specifically about email handlers.
Mail Handler
Create From Email
Sorry for the account switch I'm at work now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This option is very helpful, actually this Service Management project is running with a Mail Server that creates the tickets in the project.
The issue here is that, in this use case, we are receiving Feedback from a third party app called Appzi. Once this feedback is sent to the email set in the Mail Server, the ticket is created and the Reporter is a generic email "info@appzi.io" .
That is the reason I would like to develop a script to set the right Reporter automatically which is contained in the feedback description (which is the Description in the ticket) as an email (which would be the right Reporter, every time might be a different email). The regex provided is able to get this email from a paragraph, but from there, that is the challenge :).
I will have a look on those documents to see if somehow I could achieve that, instead of a custom script, but I think this last one is the only option.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So here's one for you sorry still busy but based on your information about Service Management.
Email Scriptrunner Jira Service Management'
This is only an example however, like you don't need to create the attachement.
What you need to focus on is getting the email body parsing it and setting the reporter to that value instead of grabbing the sender information.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry again to bother you. I haven´t find how to develop this script yet.
I tried in Cloud with automation and it works:
This automation takes the email from description, sets it in a custom field called Email Address, then it creates a new customer if needed and then it sets the Reporter with a smart value {{customer.accountId}}
So I would like to replicate this process in Jira Data Center with Scriptrunner but honestly I dont know if the same approach is needed.
This is what I have so far but I think it doesn´t make much sense. Could you please give me a north if this is the way or something else different is needed?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Will review this for you in a little bit. I seen another post very similar, from this afternoon.
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.