This may not be the best way to do it, but this is how I did it.
I didn't use any of the modules/Import/ code at all. I removed the statements that included the Import/index.php file. Instead I created my own code to import my custom module's data. I imported a .csv file by creating a loop and using the fgetcsv function to read one line at a time. Then I created a new Bean (ex. $contactbean = new Contact(); ). Then I set the bean's fields one by one from the array returned by fgetcsv. Then simply call the Bean's save() function. If you have your vardefs set up correctly, that's all you need to do.
Using Contacts as an example, this would look like:
PHP Code:
// First line in a CSV is usually the names of the fields.
$headers = array();
$record = fgetcsv( $csv, 5000 );
foreach ( $record as $idx => $fieldname )
{
// $record is an array with the index as the key, and the field name as the value.
// Flipping the two around and storing in another array allows us to store future
// values simply by referencing the field name, not the index.
$headers[$fieldname] = $idx;
}
// Begin the main import loop
$record = fgetcsv( $csv, 5000 );
while ( $record !== false )
{
/// Create bean
$contactbean = new Contact();
// Import each field
$contactbean->first_name = record[$headers['First Name']];
$contactbean->last_name = record[$headers['Last Name']];
$contactbean->phone_home = record[$headers['Home Phone #']];
// repeat until all your fields are set
$contactbean->save();
// Get the next record
$record = fgetcsv( $csv, 5000 );
}
SugarCRM is not an easy software to develop for, at first. There is a steep learning curve, so there will be many proverbial brick walls. It is nice to have a PHP debugger, to help understand the Sugar code.
I wish you the best of luck!
Bookmarks