Skip to content

Fix Activity Contact field usage in filters

No idea if this is the right way to handle this issue. Seems a bit hack-ish.

The issue

Adding an Activity Contact field from an Activity source such as Record Type ID produces a bad query with the error "No such field". image

The query comes out similar to this:

SELECT
      `_activity`.`id` AS `id`,
      `_activity`.`source_record_id` AS `source_record_id`,
      `_activity`.`activity_type_id` AS `activity_type_id`,
      `_activity`.`subject` AS `subject`,
      `_activity`.`activity_date_time` AS `activity_date_time`,
      `_activity`.`duration` AS `duration`,
      `_activity`.`location` AS `location`,
      `_activity`.`phone_id` AS `phone_id`,
      `_activity`.`phone_number` AS `phone_number`,
      `_activity`.`details` AS `details`,
      `_activity`.`status_id` AS `status_id`,
      `_activity`.`priority_id` AS `priority_id`,
      `_activity`.`parent_id` AS `parent_id`,
      `_activity`.`is_test` AS `is_test`,
      `_activity`.`medium_id` AS `medium_id`,
      `_activity`.`is_auto` AS `is_auto`,
      `_activity`.`relationship_id` AS `relationship_id`,
      `_activity`.`is_current_revision` AS `is_current_revision`,
      `_activity`.`original_id` AS `original_id`,
      `_activity`.`result` AS `result`,
      `_activity`.`is_deleted` AS `is_deleted`,
      `_activity`.`campaign_id` AS `campaign_id`,
      `_activity`.`engagement_level` AS `engagement_level`,
      `_activity`.`weight` AS `weight`,
      `_activity`.`is_star` AS `is_star`,
      `_activity`.`created_date` AS `created_date`,
      `_activity`.`modified_date` AS `modified_date`,
      `_activity_contact`.`activity_id` AS `activity_contact_activity_id`,
      `_activity_contact`.`contact_id` AS `activity_contact_contact_id`,
      `_activity_contact`.`record_type_id` AS `activity_contact_record_type_id`,
      `_activity_case`.`case_id` AS `activity_case_case_id`
    FROM
      `civicrm_activity` `_activity`
      INNER JOIN `civicrm_activity_contact` `_activity_contact` ON `_activity`.`id` = `_activity_contact`.`activity_id`
      LEFT JOIN `civicrm_case_activity` `_activity_case` ON `_activity`.`id` = `_activity_case`.`activity_id`
    WHERE
      1
      AND `activity`.`activity_contact_record_type_id` IN (1)

activity_contact_record_type_id does not exit. It looks like there is quite a bit of special handing for this table.

Merge request reports

Loading