Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Rest API Groovy in a loop



Have a post function which gets a custom field containing email addresses separated by semicolons. Able to parse them and ideally wanted to do a POST to create users. 

Only the first user gets created, then it errors out 

Here is the code: 

//Parse Emails
def users = customFieldManager.getCustomFieldObject("customfield_10100")
def userlist = issue.getCustomFieldValue(users).toString()
String[] emails = userlist.split(";")
String out = ""

//Iterate Emails and Create Users via REST
for(String email in emails){out += email.split("@")[0]

def http3 = new HTTPBuilder("http://localhost:8080/rest/api/2/user")
http3.request(POST, ContentType.JSON){
requestContentType = ContentType.JSON
request.addHeader("Authorization: Basic YWRtaW46YWRtaW4=", "ContentType: application/json")
body = [
name: email,
emailAddress: email,
displayName: email.split("@")[0],

response.success = { resp, JSON -> return JSON }
response.failure = { resp, JSON -> return JSON }

Here is the error I'm getting:

2018-05-07 14:07:21,000 http-nio-8080-exec-10 ERROR admin 847x502x2 1xxytla /secure/CommentAssignIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: PROYEC-1, actionId: 91, file: <inline script> 



at org.apache.http.impl.client.CloseableHttpClient.execute(

at org.apache.http.impl.client.CloseableHttpClient.execute(




at$ Source)



Wondering if there's some sort of pause I should do, as logs show the first user gets created, the POST is made but there's something making subsequent calls fail... 


1 answer

1 accepted

1 vote
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.
May 25, 2018

Hi Patrice, 

Instead of collecting and iterating through emails why not iterating through the list of the applications users, where each Application user holds the email address and the display name. 

Or even collect in a map the email address (as a key) and the display name (as a value) and the iterate through this map. 

Example code

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

def issue = issue as MutableIssue
def users = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10100")
def userlist = issue.getCustomFieldValue(users) as List <ApplicationUser>

def emailAndNameMap = userlist?.collectEntries {
[(it.emailAddress) : it.displayName]

userlist?.each {
log.debug "Email address $it.emailAddress"
log.debug "Display name $it.displayName"
//do some rest calls

One last thing why you use the REST api to create the users and not the Java API ? 

Hi Thanos, 

Many thanks for this and apologies for the delay, was away. 

Part of the 'brief' is that I only have a custom field with email addresses separated by semicolons. Users do not exist yet. I have to grab each email, parse first part and use it as DisplayName and create users on a remote Jira instance... 

Tried your method to map and .collectEntries as it.emailAddress and it.displayName but it fails as it does not know it is an email address 

groovy.lang.MissingPropertyException: No such property: emailAddress for class: java.lang.String

EDIT: I found my original method to be working, I hadn't accounted for trailing white spaces... 



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.
Jun 05, 2018

Hi Patrice, 

Oh ok, I got the use case wrong (I thought the custom field was a MultiUserPicker).

Glad that you sorted this out. 

Regards, Thanos

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events