Forums

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

Scriptrunner to add user to group in Jira Cloud.

Aisha M
Contributor
July 10, 2026

I have a script which gets the reporter ID from a service desk form and adds the user to a specific group.

I used the exact same syntax provided in the Adaptavist documentation, yet it doe snot work:  https://docs.adaptavist.com/sr4jc/latest/hapi/work-with-groups#add-users-to-a-group

 

def group = Groups.getByName('jira-developers')

// user can be added to the group by their account id
group.add('user_account_id')

 

Any help on how to fix this ?

Thank you

3 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
July 21, 2026

Hi @Aisha M

Could you try a different approach, as shown below, and see if there is any difference?

 

import groovy.json.JsonOutput

def accountId = 'user_account_id' //add the correct user account id
def groupName = 'jira-developers' //change the group type accordingly

def resp = post("/rest/api/3/group/user")
.queryString("groupname", groupName)
.header("Content-Type", "application/json")
.body(JsonOutput.toJson([accountId: accountId]))
.asObject(Map)

assert resp.status == 201 : "Failed to add user to group: ${resp.status} - ${resp.body}"
logger.info "Successfully added ${accountId} to group '${groupName}'"
I'm suggesting the approach above because the documentation uses ScriptRunner's HAPI to simplify the code. It is compatible with JSM, but it may need some fine-tuning.

So if the approach above works, but the suggested approach in the documentation fails, it will be good to raise a ticket here: https://the-adaptavist-group-support.atlassian.net/servicedesk/customer/portal/27
Let me know how it goes.
Thank you and Kind regards,
Ram
0 votes
Joseph Chung Yin
Community Champion
July 10, 2026

@Aisha M 

Great suggestion provided by @Germán Morales .  Since this is related to Scriptrunner add-on, you can also contact the vendor directly for additional technical support.

Lastly, what is the purpose of your group?  Is this group for the portal users (reporters) only?

Please advise.

Best, Joseph

0 votes
Germán Morales
Community Champion
July 10, 2026

Hi @Aisha M , the syntax you copied is correct. The catch is that group.add(accountId) returns a boolean instead of throwing on failure, so a call that doesn't work fails completely silently unless you capture that return value.

  • Assign the result of group.add(accountId) to a variable and log it. If it comes back false, the account ID wasn't accepted, either because it isn't a genuine account ID, or because the user is already a member of the group.
  • If Groups.getByName('jira-developers') failed to find the group, calling add on that result throws an error rather than failing quietly, so if nothing is being thrown, the group lookup is fine and the account ID is where to look.
  • Print the value your script pulls from the reporter right before the add call and compare it against that user's real account ID in the Jira Cloud people directory. Passing the reporter's display name, email, or issue key instead of the account ID looks identical to the documented example but adds nothing.

Once the logged return value comes back true, the group membership has actually been written.

TAGS
AUG Leaders

Atlassian Community Events