[Vtigercrm-developers] problems with vtwsclib
Fusioncore
ml at arceva.fr
Thu Sep 24 01:48:56 PDT 2009
Thanks Prasad,
I have modifiy your solution to print the error array
if($record === false) {
echo "Creation Error! " . $client->lastError();echo print_r($client);
} else {
$accountid = $client->getRecordId($record['id']);
echo "new account id : $accountid <br />";
}
My code is based on the documentation. I think you can update it with
this for next release. It can be usefull.
Thanks,
Bruno
Franch-vTiger Manager
Prasad a écrit :
> Hi,
>
> $record = $client->doCreate($module,
> array(
> 'account_no'=>"$societe",
> 'phone'=>"$telephone2",
> 'fax'=>"$fax",
> ...
> )
> );
>
> if($record === false) {
> echo "Creation Error! " . $client->lastError();
> } else {
> $accountid = $client->getRecordId($record['id']);
> echo "new account id : $accountid <br />";
> }
>
> accountname is mandatory field which is not set in the parameters.
> This could be a reason for failure. The if condition is fine but else
> condition (on error) is not captured. Highlighted is piece of code
> that could help in debugging.
>
> Regards,
> Prasad
> vtiger Team
>
> On 9/24/09, *Fusioncore* <ml at arceva.fr <mailto:ml at arceva.fr>> wrote:
>
> Hi
> I have create a plugin for my website who create account and
> contact in
> vtiger when a customer register on the website.
> For this purpose, I use vtwsclib 1.2 with php doCreate method
> after the script creation, I test it and it work well with contact
> creation but for the account, nothing was add on vtiger.
> The method LastError was on error when I use it
>
> I paste my code if anyone have an idea of the error. See the bug
> part of
> the file around the //bug
> The include files access.php contain only url, login and password and
> the functions.php contain functions addPortalAccess and addDate
> who work
> perfectly
>
> Thanks,
> Bruno
> French-vtiger Manager
>
>
>
>
> <?php
>
> include_once('/var/www/site/access.php'); //logins site & CRM
> include_once('vtwsclib/Vtiger/WSClient.php'); //Librairie
> SOAP CRM
> include_once('/var/www/site/www/sync/functions.php');
>
> //Connexion base de données
> mysql_connect($sitedbhost,$sitedbuser,$sitedbpassword,$sitedb);
> mysql_select_db($sitedb);
>
> //Vérification si il y a des users a synchroniser
> $verif = mysql_query("SELECT NULLIF(1, (SELECT MIN(sync_crm) FROM
> users))");
> $verif1 = mysql_result($verif, 0, 0);
> //echo"$verif1";
> if ($verif1 == "")
> echo "Nothing to sync";
> else
> {
> //Comptage du nombre d'utilisateurs à synchroniser
> $test_needed = mysql_query("SELECT COUNT(0) FROM jos_users WHERE
> sync_crm=0 GROUP BY sync_crm");
> $sync_needed = mysql_result($test_needed, 0, 0);
> //*echo "number of non sync user : $sync_needed";
> while ($sync_needed >= 1) //Boucle tant qu'on a des users a
> synchroniser
> {
> $result = mysql_query("SELECT id FROM users WHERE
> sync_crm=0");
> $current_user_sync = mysql_result($result, 0, 0);
> //*echo "<br />Id of current sync user :
> $current_user_sync<br />";
>
> //Extraction des infos de l'utilisateur
>
> $user_extend = mysql_query("SELECT * FROM
> juser_extended_data WHERE user_id='$current_user_sync'");
> $ident = mysql_query("SELECT * FROM users WHERE
> id='$current_user_sync'");
> $identity = mysql_result($ident, 0, name);
> $name = explode("\n", $identity);
> // Champs pour le compte
> $prenom = $name[0];
> $nom = $name[1];
> $email = mysql_result($ident, 0, email);
> $telephone1 = mysql_result($user_extend,2 ,fvalue);
> //Champs pour le contact
> $societe = mysql_result($user_extend,1 ,fvalue);
> $telephone2 = mysql_result($user_extend,3 ,fvalue);
> $fax = mysql_result($user_extend,4 ,fvalue);
> $siret = mysql_result($user_extend,5 ,fvalue);
> $codeape = mysql_result($user_extend,6 ,fvalue);
> $secteur = mysql_result($user_extend,7 ,fvalue);
> $poste = mysql_result($user_extend,8 ,fvalue);
> $nbsalaries = mysql_result($user_extend,9 ,fvalue);
> $site = mysql_result($user_extend,10 ,fvalue);
> $adresse = mysql_result($user_extend,11 ,fvalue);
> $BP = mysql_result($user_extend,12 ,fvalue);
> $CP = mysql_result($user_extend,13 ,fvalue);
> $ville = mysql_result($user_extend,14 ,fvalue);
> $pays = mysql_result($user_extend,15 ,fvalue);
> $username = mysql_result($ident ,0, username);
> $passwd = mysql_result($ident, 0, password);
>
> //Fin d'extration des infos de l'utilisateur
> //bug start
> //Connexion au CRM
> $client = new Vtiger_WSClient($crm_url);
>
> $login = $client->doLogin($crm_username, $crm_accesskey);
> if(!$login)
> echo 'Login Failed';
> else
> {
> /**/echo "Login Successful<br />";
> $module = 'Accounts';
> $module2 = 'Contacts';
>
> $record = $client->doCreate($module,
> array(
> 'account_no'=>"$societe",
> 'phone'=>"$telephone2",
> 'fax'=>"$fax",
> 'siccode'=>"$codeape",
> 'industry'=>"$secteur",
> 'employees'=>"$nbsalaries",
> 'website'=>"$site",
> 'ship_street'=>"$adresse",
> 'ship_pobox'=>"$BP",
> 'ship_code'=>"$CP",
> 'ship_city'=>"$ville",
> 'ship_country'=>"$pays",
> 'bill_street'=>"$adresse",
> 'bill_pobox'=>"$BP",
> 'bill_code'=>"$CP",
> 'bill_city'=>"$ville",
> 'bill_country'=>"$pays",
> )
> );
>
> if($record) {
> $accountid = $client->getRecordId($record['id']);
> }
> echo "new account id : $accountid <br />";
>
> //bug end
>
> $record = $client->doCreate($module2,
> array(
> 'firstname'=>"$prenom",
> 'lastname'=>"$nom",
> 'email'=>"$email",
> 'phone'=>"$telephone1",
> 'title'=>"$poste",
> 'accountid'=>"$accountid",
> )
> );
>
> if($record) {
> $contactid = $client->getRecordId($record['id']);
> }
> echo "new contact id : $contactid <br />";
>
>
> addPortalAccess($crmdbhost,$crmdb,$crmdbuser,$crmdbpasswd,$contactid,$username,$passwd);
>
> addDate($crmdbhost,$crmdb,$crmdbuser,$crmdbpasswd,$contactid);
>
> mysql_query("UPDATE users SET sync_crm=1 WHERE
> id=$current_user_sync");
>
> $sync_needed--;
> }
> }
> }
> ?>
> _______________________________________________
> Reach hundreds of potential candidates - http://jobs.vtiger.com
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Reach hundreds of potential candidates - http://jobs.vtiger.com
More information about the vtigercrm-developers
mailing list