Forums

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

After using GroupManager to add/remove groups, getGroupNamesForUser returns old values

Derek Fields _RightStar_
Community Champion
October 14, 2021

I have a script that I use to add and remove users from groups. At the start of the script, I call

ComponentAccessor.getGroupManager().getGroupNamesForUser(user)

to get the current list of groups for the user. After I have added and/or removed groups, I call it again. Instead of showing the new list of groups, I get the same list that I received from the first call. 

It appears to me that this is either calling an index or a cache that is not being refreshed. However, when I look at the user in the User Management view, I can see that the correct actions have been taken.

Any suggestions on what call I should be making in conjunction or instead of this approach?

1 answer

1 accepted

1 vote
Answer accepted
Reece Lander _ScriptRunner - The Adaptavist Group_
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.
October 15, 2021

Hey @Derek Fields _RightStar_

GroupManager has an internal request cache of user group membership, this cache is not updated when group membership changes occur, see the following bug: JRASERVER-63095

There isn't a good workaround for this, but if you really need to see the updated memberships in the same request, you can forcibly clear all request caches, which will also clear the cache in GroupManager.

In ScriptRunner you could do that with the following code:

import com.atlassian.jira.cache.request.RequestCacheController

RequestCacheController.clearAll()

The above code could have performance implications because it forces request caches to be cleared/recomputed, but I do not know of a better solution for this problem.

Cheers,

Reece

Suggest an answer

Log in or Sign up to answer