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 idgroup.add('user_account_id')
Any help on how to fix this ?
Thank you
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.
@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
Hi @Aisha M
Could you try a different approach, as shown below, and see if there is any difference?
import groovy.json.JsonOutputdef accountId = 'user_account_id' //add the correct user account iddef groupName = 'jira-developers' //change the group type accordinglydef 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}'"
Has your question been answered?
Thank you and Kind regards,Ram
It looks like you're new here. Sign in or register to get started.