Trigger password email after create user programmatically

I am creating user from entrypoint.

User account created successfully. But system generated password mail is not triggering.

I have updated “Enable System-Generated Passwords Feature:” in admin password management.

My entry point code

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

 
 $user_name="entrypointuserlatest";
$user_hash='passwordVal@123';
$first_name='entry';
$last_name='point';
$email='entrypointuserlatest@mailionator.com';
 $username_password = md5($user_hash);
$userNameValidate = BeanFactory::getBean('Users')->retrieve_by_string_fields(array('user_name'=>$user_name));

if($userNameValidate){echo "User Name Exits"; }
else {
$bean = BeanFactory::newBean('Users'); 
$bean->user_name = $user_name;   
$bean->user_hash = $username_password;   
$bean->first_name = $first_name;   
$bean->last_name = $last_name;  
$bean->status = 'Active';
$bean->UserType = 'RegularUser';
$bean->email1 = $email;
$bean->new_password =$user_hash;
$bean->save();  //Save
$userRecordId = $bean->id;
echo $userRecordId;
}
1 Like

Hey @hamaltonxavier

Have a look at the core functionality and pin point the place where a password is generated for new users.

I can highlight here: SuiteCRM/User.php at master · salesagility/SuiteCRM · GitHub
That with your $user->User_hash you are essentially telling the system it is NOT a new user so thus don’t send an autogenerated password.

Hope that helps.