Hi i am new here.
I want to create user with the information inside email body with a email handler, scriptrunner has the option if the user is the sender, but in my case is not the sender the user-data to create is in the body.
how can i map those values from the email to variables for execute the script ??
Hey @Manuel Bastardo Castellano
If you give me an example on how the use data will appear in the email body, I think I can give you an example script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If the body of the email is
Username: ABCDE
Full Name: Jhon Doe
Email: mail
userGroup: Group_Name
then the script in your email handler will looks something like
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.MailUtils
def body = MailUtils.getBody(message)
def tokenized = body.split("\n")
def username = tokenized[0].split("Username: ")[1]
def fullName = tokenized[1].split("Full Name: ")[1]
def email = tokenized[2].split("Email: ")[1]
def userGroup = tokenized[3].split("userGroup: ")[1]
// you will need a 'bot' with permissions to create new users
def botUser = ComponentAccessor.userManager.getUserByKey("bot")
// add a password for the new user
def password = "password"
def newCreateRequest = UserService.CreateUserRequest.withUserDetails(botUser, username, password, email, fullName).sendNotification(true)
def createValidationResult = ComponentAccessor.getComponent(UserService).validateCreateUser(newCreateRequest)
assert createValidationResult.isValid() : createValidationResult.errorCollection
This snippet is to just give you an idea. You will need to have some checks, for example if there is body, if the tokenized is not empty, etc ...
You could also use some regex magic to extract the information you want.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Manuel Bastardo Castellano
Only option what I see is get this information from issue description and then create user using script runner.
Helpful links:
- working with strings in groovy - https://www.tutorialspoint.com/groovy/groovy_strings.htm
- create user using script runner - https://library.adaptavist.com/entity/create-a-user-in-jira
Regards,
Sebastian
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.