Posted on 27/10/2026 10:57:45
Hi Imar,
The prooblem is that a user and their group memberships are saved in two separate steps. UserManagementServices.Users.Save(user) writes the user record and then raises UserSaved. Group memberships are written afterwards by a separate call to UserManagementServices.Users.AddGroupRelations(user, groups), and that call needs the user to exist already. Everything that creates users does it in that order: the user modules, checkout, forms and so on. So:
- For a new user, UserSaved always fires before any group has been assigned, so GetGroups() returns nothing.
- For an existing user, UserSaved gives you the memberships from before the current edit.
user.Groups (now obsolete; use user.GetGroups()) holds no state of its own. It reads the memberships from the database when you call it, so it can only return what has been saved so far.
There's currently no notification for when a user is added to or removed from a group, so there isn't another subscriber you can switch to.
Workarounds
- If your own code assigns the group, do the copy-down right after your AddGroupRelations call. At that point the relation exists and user.GetAncestorGroups() will find the SystemAccount parent.
- If you can find the account group from user data such as the customer number, you can skip membership entirely: UserManagementServices.UserGroups.GetGroupsByCustomerNumber(user.CustomerNumber) inside UserSaved.
- Otherwise, move the copy-down out of the save, for example into a scheduled task that syncs the fields from the parent account group to its users.
BR, Dmitrij