I had need to extend the Employee bean (which in turn extends User), so I created a custom module - added the fields I need to the vardefs in my custom module, all that's well and good.
Because of client requirements, I've also extended the REST API to allow creation of new, extended Employee objects via REST. And this is where I've run into issues. The issue I'm running into now is that certain fields aren't populating in my newly created Employee - among them, user_name, and email1. I've found that I *can* populate them if I create a User() object, either first or second, and use the common id to retrieve the corresponding Employee or User object. It just seems silly to have to load an additional bean to save certain fields, so I suspect that there may be an issue with my implementation. As it stands now - there really isn't any functional change to the extended Bean - for all intents and purposes it looks like this:
Code:
require_once('modules/Employees/Employee.php');
class myEmployee extends Employee {
// a few additional vars declared here - but I don't know that even this is particularly necessary
function Employee(){
parent::Employee();
}
} in my REST Impl file, I have a function:
Code:
public function create_myEmployee($session, $first_name, $last_name, $user_name, $title, $pass, $email, $eteam, $office) {
//session testing code omitted
$e = new myEmployee();
$e->first_name = $first_name;
$e->last_name = $last_name;
$e->user_hash = $pass; //pre-encrypted prior to send, even though it's a localhost connection
$e->user_name = $user_name;
$e->title = $title;
$e->email1 = $email;
$e->eteam = $eteam;
$e->office_id = $office;
$e->save();
return array('emp_id' => $e->id);
} which works - except that neither the user_name or email1 get saved to the myEmployee object. However, if I change it to
everything but my extended fields gets saved. So I've moved to creating the User object, saving, creating a new myEmployee bean, retrieving based on the User->id, and saving the extended fields. This just seems really inefficient to me, so I'm wondering what, if anything, I'm missing, and whether there's a cleaner way to achieve this. I also need to dig in and figure out how to pass in the password to the user object - I note in the example install UserDemoData.php (as cited in this post http://www.sugarcrm.com/forums/showthread.php?t=30692) that the password creation step is commented out - so what's the appropriate way to assign a pass in this process.
Any thoughts would be greatly appreciated. FWIW - this is for CE 5.5.x.
Bookmarks