I want to retain security role of user on change of business unit.
For this I wrote a plugin and followed below steps but not able to get the user's existing roles on change of BU.
1. Get the BU and user id from the pre entity image.
2. Get the new BU from the target entity
3. Get the existing roles name of user using the query expressions - roles are getting blank (got user roles when passed user id of another user on which BU change event is not occurring )
4. Get the new role id of the roles by passing the old security roles and new business unit id
5. Associate role id with the user.
Registered the plugin on system user entity on update of business unit on post operation as well as pre-operation.