vTiger Account synchronisation
Today, i tried to synchronize an external system with vtiger using custom fields. It took some time to see through the structure of the vtiger-codebase. But here is the result
ini_set(’/path/to/vtiger/installation/’);
require_once(’config.php’);
require_once(’include/logging.php’);
require_once(’include/database/PearDatabase.php’);
require_once(’modules/Users/Users.php’);
require_once(’modules/Accounts/Accounts.php’);
$username = “YourVtigerUserName”;
$log = &LoggerManager::getLogger(’importer’);
$seed_user = new Users();
$user_id = $seed_user->retrieve_user_id($username);
$current_user = $seed_user;
$current_user->retrieve_entity_info($user_id,”Users”);
// lookup accountId in vTiger
$acid = getAccountID($youridentified);
if($acid) {
echo “– Found: $acid\n”;
$account = new Accounts();
$account->retrieve_entity_info($acid,”Accounts”);
$account->mode = “edit”;
$account->id = $acid;
} else {
echo “– Not Found creating new\n”;
$account = new Accounts();
}
$account->column_fields[accountname] = $newname;
$account->column_fields[phone] = $newphone;
$account->column_fields[fax] = $newfax;
$account->save(”Accounts”);
require_once(’config.php’);
require_once(’include/logging.php’);
require_once(’include/database/PearDatabase.php’);
require_once(’modules/Users/Users.php’);
require_once(’modules/Accounts/Accounts.php’);
$username = “YourVtigerUserName”;
$log = &LoggerManager::getLogger(’importer’);
$seed_user = new Users();
$user_id = $seed_user->retrieve_user_id($username);
$current_user = $seed_user;
$current_user->retrieve_entity_info($user_id,”Users”);
// lookup accountId in vTiger
$acid = getAccountID($youridentified);
if($acid) {
echo “– Found: $acid\n”;
$account = new Accounts();
$account->retrieve_entity_info($acid,”Accounts”);
$account->mode = “edit”;
$account->id = $acid;
} else {
echo “– Not Found creating new\n”;
$account = new Accounts();
}
$account->column_fields[accountname] = $newname;
$account->column_fields[phone] = $newphone;
$account->column_fields[fax] = $newfax;
$account->save(”Accounts”);
Make sure to set the mode when you save an existing record, otherwise a new record will be created.



