Update custom user field programmatically

Hi folks

I extended the user blueprint with a custom text field:

data:
    label: Store data
    type: text

I entered some test values in the panel and successfully retrieved it with:

$user = kirby()->user($username);
$user->data()->value();

Now, I would like to programmatically change the value. I tried the following but with no effect (also no error thrown):

$user->data()->value('Test XY');

I assume this is an authorization issue since no user is logged in by the time the code gets executed. So I added:

$kirby = kirby();
$kirby->impersonate('kirby');

Still no effect. The Test XY value does not get written. Any ideas? Probably a no-brainer :wink:

Thanks & cheers

Stefan

Update: just figured out the solution. To change a field, the update functions is required. This way it works:

$user->update([
    'data' => 'test xy'
]);