Forums

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

Create user by email

Manuel Bastardo Castellano
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.
June 27, 2019

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 ??

 

 

2 answers

1 accepted

0 votes
Answer accepted
Thanos Batagiannis [Adaptavist]
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.
June 27, 2019

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. 

Soporte Ferrovial June 27, 2019

..

Thanos Batagiannis [Adaptavist]
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.
June 27, 2019

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. 

Like # people like this
0 votes
Sebastian Krzewiński
Community Champion
June 27, 2019

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events