Answers.Body: <p>It turned out that the client ID in the case view is missing. That's because the case view is opened from SearchKit table which has a linked column &quot;Case-ID&quot;. That link URL is generated by the SearchKit Table without the parameter <code>cid</code>. I have another table - which was probably build from a different SearchKit version (the UI is different) - that generates the link correctly.</p>
  <p>SearchKit table link configuration with <code>cid</code> parameter:
  <a href="https://i.sstatic.net/YUC8dlx7.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YUC8dlx7.jpg" alt="Working SearchKit table link configuration" /></a></p>
  <p>SearchKit table link configuration without <code>cid</code> parameter:
  <a href="https://i.sstatic.net/v1xAWOo7.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/v1xAWOo7.jpg" alt="Non-working SearchKit table link configuration" /></a></p>
  <p>Not sure how to proceed with this. Open another question?</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-01T22:58:34.083Z
Answers.Text: probably best too and tag it as searchkit or jump over to https://chat.civicrm.org/civicrm/channels/search-improvements
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-28T16:15:31.603Z
Answers.Text: Thanks for writing this up. Had the same issue.
Answers.UserDisplayName: lbl
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-28T16:26:45.240Z
Answers.Text: Oh, i solved it with the following custom output civicrm/contact/view/case?action=view&reset=1&id=[id]&cid=[Case_CaseContact_Contact_01.id] in the search kit configs.
Answers.UserDisplayName: lbl
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-01T21:16:40.443Z
Answers.LastActivityDate: 2024-05-01T21:16:40.443Z
Answers.UserDisplayName: Jan
Body: <p>I am using three different case types on two of which I am getting a DB contraint violation when changing the case status. The failing SQL-query is the following:</p>
  <pre><code>INSERT INTO `civicrm_activity_contact` (`activity_id` , `contact_id` , `record_type_id` ) VALUES ( 6204 ,  0 ,  3 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`drupal`.`civicrm_activity_contact`, CONSTRAINT `FK_civicrm_activity_contact_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
  </code></pre>
  <p>The contact_id of 0 looks somewhat suspicious to me. Any ideas what's going wrong here?</p>
  <p>I am on 5.72.2.</p>
  <p>Stacktrace:</p>
  <pre><code>[debug] $backTrace = #0 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Error.php(443): CRM_Core_Error::backtrace(&quot;backTrace&quot;, TRUE)
  #1 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(39): CRM_Core_Error::handleUnhandledException(Object(Civi\Core\Exception\DBQueryException))
  #2 /opt/drupal/web/modules/contrib/civicrm/src/Civicrm.php(88): CRM_Core_Invoke::invoke((Array:3))
  #3 /opt/drupal/web/modules/contrib/civicrm/src/Controller/CivicrmController.php(83): Drupal\civicrm\Civicrm-&gt;invoke((Array:3))
  #4 [internal function](): Drupal\civicrm\Controller\CivicrmController-&gt;main((Array:3), &quot;&quot;)
  #5 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array((Array:2), (Array:2))
  #6 /opt/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}()
  #7 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
  #8 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext((Array:2), (Array:2))
  #9 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}()
  #10 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
  #11 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #12 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #13 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #14 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\ContentLength-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #15 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #16 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #17 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #18 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #19 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #20 /opt/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #21 /opt/drupal/web/index.php(19): Drupal\Core\DrupalKernel-&gt;handle(Object(Symfony\Component\HttpFoundation\Request))
  #22 {main}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-27T11:41:33.717Z
Comments.Text: It looks like it can't figure out the case client. Is there anything unusual about the client? e.g are they in trash (soft deleted)?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-27T12:53:48.457Z
Comments.Text: It doesn't seem to depend on the case client but on the case type. The same client on a different case type works fine.
Comments.UserDisplayName: Jan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-27T13:07:28.663Z
Comments.Text: Do you have a stack trace? From [ConfigAndLog](https://civicrm.stackexchange.com/questions/15931/where-are-the-configandlog-and-templates-c-directories).
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-27T19:06:27.870Z
Comments.Text: I added the backtrace above. There ist also a verbose log entry [error] 
  $Fatal Error Details. Let me know if that's helpful.
Comments.UserDisplayName: Jan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-28T22:55:56.810Z
Comments.Text: Unfortunately that stack trace only says "something happened during the page run". I'd be looking for a stack trace that shows what file and what line number is generating the INSERT, and the list of which function(s) called it. Is that in the Fatal Error Details?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-29T12:05:12.170Z
Comments.Text: Find the full log entry here: https://ctxt.io/2/AAAoJgtKEw
Comments.UserDisplayName: Jan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-29T13:09:01.880Z
Comments.Text: It looks normal (except of course the error). It still seems like it's not able to determine the case client, like something is going wrong [here](https://github.com/civicrm/civicrm-core/blob/7fc628b7e50271b2952209525d929434b8ec9ef4/CRM/Case/Form/Activity.php#L422).
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-01T21:17:22.727Z
Comments.Text: Thank you! See the result below.
Comments.UserDisplayName: Jan
Tags: <civicase>
Title: DB Error: constraint violation on changing case status
ThreadText: # DB Error: constraint violation on changing case status
  
  (Asked by: username_0 on 2024-04-27)
  
  I am using three different case types on two of which I am getting a DB contraint violation when changing the case status. The failing SQL-query is the following:
  
  ```
  INSERT INTO `civicrm_activity_contact` (`activity_id` , `contact_id` , `record_type_id` ) VALUES ( 6204 ,  0 ,  3 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`drupal`.`civicrm_activity_contact`, CONSTRAINT `FK_civicrm_activity_contact_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
  
  ```
  
  The contact\_id of 0 looks somewhat suspicious to me. Any ideas what's going wrong here?
  
  I am on 5.72.2.
  
  Stacktrace:
  
  ```
  [debug] $backTrace = #0 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Error.php(443): CRM_Core_Error::backtrace("backTrace", TRUE)
  #1 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(39): CRM_Core_Error::handleUnhandledException(Object(Civi\Core\Exception\DBQueryException))
  #2 /opt/drupal/web/modules/contrib/civicrm/src/Civicrm.php(88): CRM_Core_Invoke::invoke((Array:3))
  #3 /opt/drupal/web/modules/contrib/civicrm/src/Controller/CivicrmController.php(83): Drupal\civicrm\Civicrm->invoke((Array:3))
  #4 [internal function](): Drupal\civicrm\Controller\CivicrmController->main((Array:3), "")
  #5 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array((Array:2), (Array:2))
  #6 /opt/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
  #7 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
  #8 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext((Array:2), (Array:2))
  #9 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
  #10 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
  #11 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #12 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #13 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #14 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #15 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #16 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #17 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #18 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #19 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #20 /opt/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #21 /opt/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
  #22 {main}
  
  ```
  
  **Tags:** civicase
  
  > **Comments:**
  > **username_1**: It looks like it can't figure out the case client. Is there anything unusual about the client? e.g are they in trash (soft deleted)?  
  > **username_0**: It doesn't seem to depend on the case client but on the case type. The same client on a different case type works fine.  
  > **username_1**: Do you have a stack trace? From [ConfigAndLog](https://civicrm.stackexchange.com/questions/15931/where-are-the-configandlog-and-templates-c-directories).  
  > **username_0**: I added the backtrace above. There ist also a verbose log entry [error]  $Fatal Error Details. Let me know if that's helpful.  
  > **username_1**: Unfortunately that stack trace only says "something happened during the page run". I'd be looking for a stack trace that shows what file and what line number is generating the INSERT, and the list of which function(s) called it. Is that in the Fatal Error Details?  
  > **username_0**: Find the full log entry here: https://ctxt.io/2/AAAoJgtKEw  
  > **username_1**: It looks normal (except of course the error). It still seems like it's not able to determine the case client, like something is going wrong [here](https://github.com/civicrm/civicrm-core/blob/7fc628b7e50271b2952209525d929434b8ec9ef4/CRM/Case/Form/Activity.php#L422).  
  > **username_0**: Thank you! See the result below.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-05-01. Score: 1
  
  It turned out that the client ID in the case view is missing. That's because the case view is opened from SearchKit table which has a linked column "Case-ID". That link URL is generated by the SearchKit Table without the parameter `cid`. I have another table - which was probably build from a different SearchKit version (the UI is different) - that generates the link correctly.
  
  SearchKit table link configuration with `cid` parameter:
  [![Working SearchKit table link configuration](https://i.sstatic.net/YUC8dlx7.jpg)](https://i.sstatic.net/YUC8dlx7.jpg)
  
  SearchKit table link configuration without `cid` parameter:
  [![Non-working SearchKit table link configuration](https://i.sstatic.net/v1xAWOo7.jpg)](https://i.sstatic.net/v1xAWOo7.jpg)
  
  Not sure how to proceed with this. Open another question?
  
  > **Comments:**
  > **username_2**: probably best too and tag it as searchkit or jump over to https://chat.civicrm.org/civicrm/channels/search-improvements  
  > **username_3**: Thanks for writing this up. Had the same issue.  
  > **username_3**: Oh, i solved it with the following custom output civicrm/contact/view/case?action=view&reset=1&id=[id]&cid=[Case_CaseContact_Contact_01.id] in the search kit configs.  
  
  ---
  
  