AnsweredAssumed Answered

Error saviing new users from code

Question asked by jlabuelo on Jun 18, 2015
Good Morning all

I am trying to create a new user by custom code in Sugar CE 6.5. The code seems to work, the user appears in the list of users, also the user table in the DB seems to be ok, if I try to log in using this username and password the user is able to log in..., however if I try to Edit the user to change the password using the Admin user, when I click on save, an error appears in the SugarCRM screen.

"There is already an existing user with this username, please select a new username for this user before saving changes."

Why is this happening?

Here is the code I use to create the user.

Thanks a lot!!

$sugar_user = new User(); 
$sugar_user->user_name=$vet_act->identificador;
$sugar_user->first_name=$vet_act->first_name;
$sugar_user->last_name=$vet_act->last_name;
$sugar_user->phone_home=$vet_act->phone_home;
$sugar_user->phone_mobile=$vet_act->first_mobile;
$sugar_user->email1=$vet_act->email1;
$sugar_user->tipo_usuario_regiac_c="Vet_Act";
$sugar_user->num_colexiado_c=$vet_act->num_colexiado;
$sugar_user->licencia_c=$vet_act->licencia;
$sugar_user->address_street=$vet_act->primary_address_street;
$sugar_user->address_state=$vet_act->primary_address_state;
$sugar_user->address_city=$vet_act->primary_address_city;
$sugar_user->address_country=$vet_act->primary_address_country;
$sugar_user->address_postalcode=$vet_act->primary_address_postalcode;
$sugar_user->sugar_login='1';
$sugar_user->is_admin='0';
$sugar_user->status=$vet_act->estado;
$sugar_user->employee_status = $vet_act->estado;
$sugar_user->user_hash=md5($vet_act->contrasena);
$sugar_user->save();

Outcomes