Documentation

EventHistory

API


EventHistory - service for writing item/element's history.

Writes element's handling-action into CRM history (for deal, quote, SPA): viewing, deleting, updating. For example, history can contain information about which field was edited, its old and new value.

History can be found in the "History" tab in element details.

The service \Bitrix\Crm\Service\EventHistory and auxiliary classes were created to provide history of actions with SPAs and quotes.

Class object EventHistory - is a service, retrieved via container. It's designed to register an event associated with an element. Most often, its updating, viewing and etc.

Correspondingly, class has a class of public register* methods called to register an event. For example, registerUpdate is called to register an element update. All these methods return object \Bitrix\Main\Result containing errors if something went wrong.

All register* methods receive class object EventHistory\TrackedObject, retrieved via factory. EventHistory\TrackedObject prepares data for writing an event. Completed data is passed as object EventHistory\EventHistoryData.

Example


Register an element view
use Bitrix\Crm\Service\Container;

$factory = Container::getInstance()->getFactory(\CCrmOwnerType::Quote);

$item = $factory->getItem(1);

$trackedObject = $factory->getTrackedObject($item);

/** @var \Bitrix\Main\Result $result */
$result = Container::getInstance()->getEventHistory()->registerView($trackedObject);
© «Bitrix24», 2001-2024
Up