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
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}'"
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Once the logged return value comes back true, the group membership has actually been written.
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.