I updated some user properties (e.g. roles, groups, preferences) via script. The changes are lost after the server was restarted. What went wrong?
Let's assume you have built a small user management system where you can change a user's properties:
- Set a first name
- Set a last name
- Add the user to a group
- Set a preference (e.g. a phone number)
- Set a new user password
In the end, the final assignment is done in a Script Function like this:
User $user := User:Get($userId);
$user.setFirstName($firstName);
$user.setLastName($lastName);
UserAddToGroup($userId, 'Customer');
$user.setPreference('Phone', '12345678');
String $encryptedPassword := User:HashPassword('Test1234&');
$user.setEncryptedPassword($encryptedPassword);
This is all fine. But:
IMPORTANT: These changes remain in memory only until you actively force the User Service to persist them.
Add the following line of code to persist these changes:
User:Update($user)
Note: Similarly, when creating a new user with User:Create(), this user also needs to be persisted using User:AddUser().