我用过PHP Client library for Exact Online。
我需要根据记录是否存在来存储记录。由于记录已成功保存。但是很遗憾,记录没有更新。
$customer = [
'address' => 'No.22/N, 91 Cross, XYZ Street, ABC Road',
'address2' => 'DEF',
'city' => 'GHI',
'customerid' => '999',
'country' => 'DE',
'name' => 'Nishanth',
'zipcode' => '123456'
];
// Create a new account
$account->AddressLine1 = $customer['address'];
$account->AddressLine2 = $customer['address2'];
$account->City = $customer['city'];
$account->Code = $customer['customerid'];
$account->Country = $customer['country'];
$account->IsSales = 'true';
$account->Name = $customer['name'];
$account->Postcode = $customer['zipcode'];
$account->Email = 'nishanth@gmail.com';
$account->Status = 'C';
根据上面的代码,需要根据条件从以下代码段中更新或保存记录。遵循两种方法:
我采用的方法:
if($AccInfo)
{ // Update
$AccInfo->AddressLine1 = $customer['address'];
$AccInfo->AddressLine2 = $customer['address2'];
$AccInfo->City = $customer['city'];
$updateAcc = $AccInfo->update();
}
else
{ // Save
$savedAcc = $Accounts->save();
}
结果:
Warning: Attempt to assign property 'AddressLine1' of non-object in E:\xampp\htdocs\exact-php-client-master\example\example.php on line 506
Warning: Attempt to assign property 'AddressLine2' of non-object in E:\xampp\htdocs\exact-php-client-master\example\example.php on line 507
Warning: Attempt to assign property 'City' of non-object in E:\xampp\htdocs\exact-php-client-master\example\example.php on line 508
Fatal error: Uncaught Error: Call to a member function update() on array in E:\xampp\htdocs\exact-php-client-master\example\example.php:510 Stack trace: #0 {main} thrown in E:\..\..\exact-php-client-master\example\example.php on line 510
II方法:
if($AccInfo)
{ // Update
$updateAcc = $Accounts->update();
}
else
{ // Save
$savedAcc = $Accounts->save();
}
结果:
Picqer\Financials\Exact\ApiException : Error 400: Bad Request - Error in query syntax.
我们应该如何将记录更新为“精确在线仪表板”?
答案 0 :(得分:0)
最后,我通过编写自定义方法解决了该问题
$AccInfo = $Accounts->filter("Email eq 'nishanthjay@gmail.com'");
if($AccInfo)
{ // Update
$updateAcc = $Accounts->customUpdate($AccInfo[0]->ID);
echo '<pre>'; print_r($updateAcc);
}
else
{ // Save
$savedAcc = $Accounts->save();
}
我从..\src\Picqer\Financials\Exact\Persistance\Storable.php
public function customUpdate($primaryKey='')
{
$this->fill($this->update2($primaryKey));
return $this;
}
public function update2($primaryKey='')
{
return $this->connection()->put($this->url() . "(guid'$primaryKey')", $this->json());
}
对于任何确切知道如何更新到ExactOnline的人。始终欢迎您通过称为update()
的内置函数来回答发布的问题。