Skip to content

Instantly share code, notes, and snippets.

@ginkgomzd
Last active August 29, 2015 14:04
Show Gist options
  • Save ginkgomzd/c8dd86a05ad4bf6a8a92 to your computer and use it in GitHub Desktop.
Save ginkgomzd/c8dd86a05ad4bf6a8a92 to your computer and use it in GitHub Desktop.
Reassign Inbound Emails
CREATE ALGORITHM=UNDEFINED DEFINER=`mzd`@`localhost` SQL SECURITY DEFINER VIEW `find_inbound_emails`
AS select
`opt`.`name` AS `record_type`
,`ac`.`record_type_id` AS `record_type_id`
,`act`.`id` AS `id`
,`act`.`subject` AS `subject`
,`act`.`activity_date_time` AS `activity_date_time`
,`ac`.`contact_id` AS `contact_id`
,`cont`.`display_name` AS `display_name`
FROM (((`civicrm_activity` `act`
left join `civicrm_activity_contact` `ac` on((`act`.`id` = `ac`.`activity_id`)))
left join `civicrm_contact` `cont` on((`ac`.`contact_id` = `cont`.`id`)))
join `civicrm_option_value` `opt` on(((`opt`.`option_group_id` = 61) and (`opt`.`value` = `ac`.`record_type_id`))))
WHERE (`act`.`activity_type_id` = 12) ORDER BY `act`.`activity_date_time`
DESC ;
-- SAMPLE Reassign inbound email to a new contact
-- could also use record_type_id, clearly
UPDATE find_inbound_emails set contact_id = 19 WHERE id = 164 AND record_type = 'Activity Targets';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment