Read cost center
Reads one cost center: the code from the command line, or else the first cost center.
get() returns a CostCenter, or throws a DimensionNotFoundException when the code does not exist. Use find() to get null instead. A code that does not match the code format of the company cannot exist, so it is also “not found”.
A cost center has a name of at most 80 characters and these read-only fields:
status:DimensionStatus::Active,DeletedorHidden(deleted while in use).inUse: whether the cost center is used in a transaction.behaviour:normal,systemortemplate.touched: how often the cost center was changed, andmodified: the last change.
The other dimension fields (short name, periods, website, …) are not in use for cost centers, so the SDK leaves them out.
$twinfield = Example::twinfield();
// The code from the command line, or else the first cost center.$code = $argv[1] ?? $twinfield->costCenters()->search()->limit(1)->get()->items[0]->code ?? exit('The company has no cost centers.' . PHP_EOL);
try { $costCenter = $twinfield->costCenters()->get($code);} catch (DimensionNotFoundException $exception) { echo 'Not found: ', $exception->reason, PHP_EOL;
exit(1);}
echo 'Code: ', $costCenter->code, PHP_EOL;echo 'Name: ', $costCenter->name, PHP_EOL;echo 'UID: ', $costCenter->uid, PHP_EOL;echo 'Status: ', $costCenter->status->value, $costCenter->inUse ? ' (in use)' : '', PHP_EOL;echo 'Behaviour: ', $costCenter->behaviour->value, PHP_EOL;echo 'Modified: ', $costCenter->modified?->format('Y-m-d H:i') ?? '-', PHP_EOL;echo 'Changes: ', $costCenter->touched, PHP_EOL;php examples/cost-centers/read-cost-center/example.php 100Code: 100Name: SalesUID: 5f3c2a1e-7b4d-4e8f-9a6b-1c2d3e4f5a6bStatus: active (in use)Behaviour: normalModified: 2025-03-14 09:30Changes: 2Source
Section titled “Source”View examples/cost-centers/read-cost-center/example.php on GitHub.
Twinfield and Wolters Kluwer are trademarks of Wolters Kluwer. Their names and logos are used only to refer to their products.