Saving to user's custom field I am using saveUser and i am trying to save a value to a user's custom field.

        $userModel = new UserModel();
        $userModel-&gt;mycustomfield = 'test value';
        craft()-&gt;users-&gt;saveUser($userModel);


This is what i have so far.

I am getting this error:

Internal Server Error
Property "Craft\UserModel.mycustomfield" is not defined.


How do i save to a custom user field?

EDIT

Also tried:

        $user = craft()-&gt;userSession-&gt;getUser();
        $userModel = new UserModel();
        $userModel-&gt;id = $user-&gt;id;
        $userModel-&gt;getContent()-&gt;setAttributes(array(
            'mycustomfield' =&gt; 'my field value'
        ));
        craft()-&gt;users-&gt;saveUser($userModel);


No error, doesnt save either.

EDIT

$userModel-&gt;getContent()-&gt;mycustomfield = 'my value';


No error, doesnt save.

SOLUTION

    $user = craft()-&gt;userSession-&gt;getUser();
    $userModel = new UserModel();
    $userModel-&gt;id = $user-&gt;id;
    $userModel-&gt;username = $user-&gt;username;
    $userModel-&gt;email = $user-&gt;email;
    $userModel-&gt;password = '';
    $userModel-&gt;getContent()-&gt;mycustomfield = 'my custom value';
    $success = craft()-&gt;users-&gt;saveUser($userModel);
    if (!craft()-&gt;users-&gt;saveUser($userModel))
    {
        $errors = $userModel-&gt;getErrors();
    }
It's probably a validation error.  Use this to check if there are any.

$userModel-&gt;getContent()-&gt;setAttributes(array(
    'mycustomfield' =&gt; 'my field value'
));

if (!craft()-&gt;users-&gt;saveUser($userModel))
{
    $errors = $userModel-&gt;getErrors();
}