// поиск компании по телефону
$dbResultCompany = \Bitrix\Crm\FieldMultiTable::getList([
'filter' => [
'ENTITY_ID' => 'COMPANY',
'TYPE_ID' => 'PHONE',
'VALUE' => [
preg_replace("/[^0-9]/", '', $phone),
$phone,
str_replace(array( '(', ')' ), '', $phone)
]
]
]);
$findCompanyPhone = $dbResultCompany->Fetch();
\Bitrix\Main\Loader::requireModule('crm');
/**
* Телефон который будем искать
* @var string
*/
$phone = '2131164';
/**
* Список всех ID лидов с этим телефонным номером
* @var int[]
*/
$leadIds = [];
$adapter = \Bitrix\Crm\EntityAdapterFactory::create([
'FM' => [
'PHONE' => [
['VALUE' => $phone]
]
]
],
\CCrmOwnerType::Lead
);
$dups = (new \Bitrix\Crm\Integrity\ContactDuplicateChecker())
->findDuplicates(
$adapter,
new \Bitrix\Crm\Integrity\DuplicateSearchParams([
'FM.PHONE'
])
);
foreach($dups as &$dup)
{
if(!($dup instanceof \Bitrix\Crm\Integrity\Duplicate))
{
continue;
}
$entities = $dup->getEntities();
if(!(is_array($entities) && !empty($entities)))
{
continue;
}
//Each entity type limited by 50 items
foreach($entities as &$entity)
{
if(!($entity instanceof \Bitrix\Crm\Integrity\DuplicateEntity))
{
continue;
}
if ( $entity->getEntityTypeID() != \CCrmOwnerType::Lead)
{
continue;
}
$leadIds[] = $entity->getEntityID();
}
}