Specify target contact ID when creating case activities in sequence
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 17 Dec 2018 21:25:08 +0000 (21:25 +0000)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 17 Dec 2018 23:11:05 +0000 (23:11 +0000)
Civi/CCase/SequenceListener.php

index 2709749a947ce9bcb6d8fc8e5139193d2b44d91f..cd60e81575bcf5e948dee7629795be0e66193117 100644 (file)
@@ -120,7 +120,12 @@ class SequenceListener implements CaseChangeListener {
       'activity_date_time' => \CRM_Utils_Time::getTime('YmdHis'),
       'case_id' => $analyzer->getCaseId(),
     );
-    $r = civicrm_api3('Activity', 'create', $params);
+    $case = $analyzer->getCase();
+    if (!empty($case['contact_id'])) {
+      $params['target_id'] = \CRM_Utils_Array::first($case['contact_id']);
+    }
+
+    civicrm_api3('Activity', 'create', $params);
     $analyzer->flush();
   }