Answers.Body: <p>When stored in files the definition field is null.</p>
  <p>See also <a href="https://civicrm.stackexchange.com/questions/34375/what-are-the-pros-and-cons-of-using-external-xml-files-for-civicase-configuratio">What are the pros and cons of using external xml files for CiviCase configuration?</a></p>
  <p>But if you just want to consolidate all under one type, just turn off the hook extension and run a SQL statement <code>update civicrm_case set case_type_id=1</code>, and then delete all the case types except id 1 and set is_active manually to 1 for it. Then configure the activities for the type in the UI.</p>
  <p>Also move all the xml files out of the way.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-22T01:29:22.867Z
Answers.Text: Thanks for responding, @Demerit, I really appreciate it. Worked like a charm!
  
  I ended up using 9 instead of 1 because the name with the spaces was still causing issues and I was unable to load the UI. Refreshed db, followed you directions and set everything to ID 9 instead. Worked like a dream and I was able to create a new generic case type.
  
  Thank you, again.
  
  Update: unfortunately, I don't have enough of a rep to upvote your answer but my feedback was recorded.
Answers.UserDisplayName: Charlotta Beavers
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-22T01:30:32.713Z
Answers.Text: Great, glad it worked out.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-22T21:18:23.823Z
Answers.Text: add a couple of more comments here so we can upvote them (if they are nice comments)
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-22T00:32:11.563Z
Answers.LastActivityDate: 2021-06-22T00:32:11.563Z
Answers.UserDisplayName: Demerit
Body: <p>I have a Drupal/CiviCRM instance (v 5.19.3) that I have inherited. It seems much of the custom work was done prior to version 4.6. And then it was upgraded to 5.19.3 without updating the customizations. One customization is the case types. They appear in two locations, a Civi extension (xml/case/*.xml) and under custom templates (sites/all/custom_templates/CRM/Case/xml/configuration) - yes, the directory setting for the custom templates is correctly set. Both directories contain the same files, which at this point are customized versions of the Civi core HRD xml files (sites/all/modules/civicrm/CRM/Case/xml/HRD).</p>
  <p>When I attmept to load the Civi Case Types page (https://[site]/civicrm/admin/options/case_type?reset=1), I am getting an fatal error. This happens regardless of whether I attempt to load the types from the menu or using the API.</p>
  <ul>
  <li>civicrm/ajax/rest?entity=CaseType&amp;action=get&amp;json=%7B%22options%22%3A%7B%22limit%22%3A0%7D%7D
  - <strong>message: $Fatal Error Details = Array ( [message] =&gt; [code] =&gt; )</strong></li>
  </ul>
  <p>Back Trace:</p>
  <blockquote>
  <p>$backTrace = #0 /var/www/instance/sites/all/modules/civicrm/CRM/Core/Error.php(343): CRM_Core_Error::backtrace(&quot;backTrace&quot;, TRUE) #1 /var/www/instance/sites/all/modules/civicrm/CRM/Core/DAO.php(1195): CRM_Core_Error::fatal() #2 /var/www/instance/sites/all/modules/civicrm/CRM/Case/XMLRepository.php(96): CRM_Core_DAO::getFieldValue(&quot;CRM_Case_DAO_CaseType&quot;, &quot;&quot;, &quot;definition&quot;, &quot;name&quot;) #3 /var/www/instance/sites/all/modules/civicrm/api/v3/CaseType.php(102): CRM_Case_XMLRepository-&gt;retrieve(&quot;&quot;) #4 /var/www/instance/sites/all/modules/civicrm/api/v3/CaseType.php(81): _civicrm_api3_case_type_get_formatResult((Array:4), (Array:5)) #5 /var/www/instance/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(101): civicrm_api3_case_type_get((Array:3)) #6 /var/www/instance/sites/all/modules/civicrm/Civi/API/Kernel.php(168): Civi\API\Provider\MagicFunctionProvider-&gt;invoke((Array:9)) #7 /var/www/instance/sites/all/modules/civicrm/Civi/API/Kernel.php(99): Civi\API\Kernel-&gt;runRequest((Array:9)) #8 /var/www/instance/sites/all/modules/civicrm/api/api.php(23): Civi\API\Kernel-&gt;runSafe(&quot;CaseType&quot;, &quot;get&quot;, (Array:3), NULL) #9 /var/www/instance/sites/all/modules/civicrm/CRM/Utils/REST.php(316): civicrm_api(&quot;CaseType&quot;, &quot;get&quot;, (Array:3)) #10 /var/www/instance/sites/all/modules/civicrm/CRM/Utils/REST.php(566): CRM_Utils_REST::process((Array:3), (Array:3)) #11 /var/www/instance/sites/all/modules/civicrm/CRM/Core/Invoke.php(256): CRM_Utils_REST::ajax() #12 /var/www/instance/sites/all/modules/civicrm/CRM/Core/Invoke.php(84): CRM_Core_Invoke::runItem((Array:12)) #13 /var/www/instance/sites/all/modules/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke((Array:3)) #14 /var/www/instance/sites/all/modules/civicrm/drupal/civicrm.module(444): CRM_Core_Invoke::invoke((Array:3)) #15 /var/www/instance/includes/menu.inc(517): civicrm_invoke(&quot;ajax&quot;, &quot;rest&quot;) #16 /var/www/instance/index.php(21): menu_execute_active_handler() #17 {main}</p>
  </blockquote>
  <p>The definitions for the Case Types in the database are set to NULL. Is the definition value supposed to be an array based on the XML activity types listed in the xml file? Note that it seems the old names/titles were only slightly different. At this point there are cases for each of the IDs listed below. All of the activity types listed in the xml's are the same for each case and the client would like to consoldiate all the Cases under one Case Type. The Civi extension calls a hook_civicrm_caseTypes when it is enabled and disabled. And though this hook is being called, it only updates is_active field to true or false based on being enabled or disabled (currently, the ones it updates have is_active set to 0, when enabled they are 1). It does not update the definitions.</p>
  <pre><code>+----+------------------------------+------------------------------+-------------+-----------+-------------+--------+------------+
  | id | name                         | title                        | description | is_active | is_reserved | weight | definition |
  +----+------------------------------+------------------------------+-------------+-----------+-------------+--------+------------+
  |  1 | Civil And Political          | Civil And Political          | NULL        |         1 |           0 |      1 | NULL       |
  |  2 | Economic Social And Cultural | Economic Social And Cultural | NULL        |         1 |           0 |      2 | NULL       |
  |  3 | Gender Issues                | Gender Issues                | NULL        |         1 |           0 |      4 | NULL       |
  |  4 | LGBT                         | LGBT                         | NULL        |         1 |           0 |      5 | NULL       |
  |  5 |                              | Environmental                | NULL        |         0 |           0 |      3 | NULL       |
  |  6 | CivilAndPolitical            | Civil And Political          | NULL        |         0 |           1 |      1 | NULL       |
  |  7 | EconomicSocialAndCultural    | Economic Social And Cultural | NULL        |         0 |           1 |      1 | NULL       |
  |  8 | Environmental                | Environmental                | NULL        |         0 |           1 |      1 | NULL       |
  |  9 | GenderIssues                 | Gender Issues                | NULL        |         0 |           1 |      1 | NULL       |
  +----+------------------------------+------------------------------+-------------+-----------+-------------+--------+------------+
  </code></pre>
  <p>Is there a way to insert the Case Type definitions from the existing xmls? Is this the approach you would use or do you have another suggestion for how I should approach this problem? How can I get the Case Types to load in the UI?</p>
  <p>I appreciate your help.</p>
  
Tags: <civicase>
Title: Is there a way to insert Case Type definitions?
ThreadText: # Is there a way to insert Case Type definitions?
  
  (Asked by: username_0 on 2021-06-22)
  
  I have a Drupal/CiviCRM instance (v 5.19.3) that I have inherited. It seems much of the custom work was done prior to version 4.6. And then it was upgraded to 5.19.3 without updating the customizations. One customization is the case types. They appear in two locations, a Civi extension (xml/case/\*.xml) and under custom templates (sites/all/custom\_templates/CRM/Case/xml/configuration) - yes, the directory setting for the custom templates is correctly set. Both directories contain the same files, which at this point are customized versions of the Civi core HRD xml files (sites/all/modules/civicrm/CRM/Case/xml/HRD).
  
  When I attmept to load the Civi Case Types page (https://[site]/civicrm/admin/options/case\_type?reset=1), I am getting an fatal error. This happens regardless of whether I attempt to load the types from the menu or using the API.
  
  * civicrm/ajax/rest?entity=CaseType&action=get&json=%7B%22options%22%3A%7B%22limit%22%3A0%7D%7D
    - **message: $Fatal Error Details = Array ( [message] => [code] => )**
  
  Back Trace:
  
  > $backTrace = #0 /var/www/instance/sites/all/modules/civicrm/CRM/Core/Error.php(343): CRM\_Core\_Error::backtrace("backTrace", TRUE) #1 /var/www/instance/sites/all/modules/civicrm/CRM/Core/DAO.php(1195): CRM\_Core\_Error::fatal() #2 /var/www/instance/sites/all/modules/civicrm/CRM/Case/XMLRepository.php(96): CRM\_Core\_DAO::getFieldValue("CRM\_Case\_DAO\_CaseType", "", "definition", "name") #3 /var/www/instance/sites/all/modules/civicrm/api/v3/CaseType.php(102): CRM\_Case\_XMLRepository->retrieve("") #4 /var/www/instance/sites/all/modules/civicrm/api/v3/CaseType.php(81): \_civicrm\_api3\_case\_type\_get\_formatResult((Array:4), (Array:5)) #5 /var/www/instance/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(101): civicrm\_api3\_case\_type\_get((Array:3)) #6 /var/www/instance/sites/all/modules/civicrm/Civi/API/Kernel.php(168): Civi\API\Provider\MagicFunctionProvider->invoke((Array:9)) #7 /var/www/instance/sites/all/modules/civicrm/Civi/API/Kernel.php(99): Civi\API\Kernel->runRequest((Array:9)) #8 /var/www/instance/sites/all/modules/civicrm/api/api.php(23): Civi\API\Kernel->runSafe("CaseType", "get", (Array:3), NULL) #9 /var/www/instance/sites/all/modules/civicrm/CRM/Utils/REST.php(316): civicrm\_api("CaseType", "get", (Array:3)) #10 /var/www/instance/sites/all/modules/civicrm/CRM/Utils/REST.php(566): CRM\_Utils\_REST::process((Array:3), (Array:3)) #11 /var/www/instance/sites/all/modules/civicrm/CRM/Core/Invoke.php(256): CRM\_Utils\_REST::ajax() #12 /var/www/instance/sites/all/modules/civicrm/CRM/Core/Invoke.php(84): CRM\_Core\_Invoke::runItem((Array:12)) #13 /var/www/instance/sites/all/modules/civicrm/CRM/Core/Invoke.php(52): CRM\_Core\_Invoke::\_invoke((Array:3)) #14 /var/www/instance/sites/all/modules/civicrm/drupal/civicrm.module(444): CRM\_Core\_Invoke::invoke((Array:3)) #15 /var/www/instance/includes/menu.inc(517): civicrm\_invoke("ajax", "rest") #16 /var/www/instance/index.php(21): menu\_execute\_active\_handler() #17 {main}
  
  The definitions for the Case Types in the database are set to NULL. Is the definition value supposed to be an array based on the XML activity types listed in the xml file? Note that it seems the old names/titles were only slightly different. At this point there are cases for each of the IDs listed below. All of the activity types listed in the xml's are the same for each case and the client would like to consoldiate all the Cases under one Case Type. The Civi extension calls a hook\_civicrm\_caseTypes when it is enabled and disabled. And though this hook is being called, it only updates is\_active field to true or false based on being enabled or disabled (currently, the ones it updates have is\_active set to 0, when enabled they are 1). It does not update the definitions.
  
  ```
  +----+------------------------------+------------------------------+-------------+-----------+-------------+--------+------------+
  | id | name                         | title                        | description | is_active | is_reserved | weight | definition |
  +----+------------------------------+------------------------------+-------------+-----------+-------------+--------+------------+
  |  1 | Civil And Political          | Civil And Political          | NULL        |         1 |           0 |      1 | NULL       |
  |  2 | Economic Social And Cultural | Economic Social And Cultural | NULL        |         1 |           0 |      2 | NULL       |
  |  3 | Gender Issues                | Gender Issues                | NULL        |         1 |           0 |      4 | NULL       |
  |  4 | LGBT                         | LGBT                         | NULL        |         1 |           0 |      5 | NULL       |
  |  5 |                              | Environmental                | NULL        |         0 |           0 |      3 | NULL       |
  |  6 | CivilAndPolitical            | Civil And Political          | NULL        |         0 |           1 |      1 | NULL       |
  |  7 | EconomicSocialAndCultural    | Economic Social And Cultural | NULL        |         0 |           1 |      1 | NULL       |
  |  8 | Environmental                | Environmental                | NULL        |         0 |           1 |      1 | NULL       |
  |  9 | GenderIssues                 | Gender Issues                | NULL        |         0 |           1 |      1 | NULL       |
  +----+------------------------------+------------------------------+-------------+-----------+-------------+--------+------------+
  
  ```
  
  Is there a way to insert the Case Type definitions from the existing xmls? Is this the approach you would use or do you have another suggestion for how I should approach this problem? How can I get the Case Types to load in the UI?
  
  I appreciate your help.
  
  **Tags:** civicase
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-06-22. Score: 4 | Accepted answer
  
  When stored in files the definition field is null.
  
  See also [What are the pros and cons of using external xml files for CiviCase configuration?](https://civicrm.stackexchange.com/questions/34375/what-are-the-pros-and-cons-of-using-external-xml-files-for-civicase-configuratio)
  
  But if you just want to consolidate all under one type, just turn off the hook extension and run a SQL statement `update civicrm_case set case_type_id=1`, and then delete all the case types except id 1 and set is\_active manually to 1 for it. Then configure the activities for the type in the UI.
  
  Also move all the xml files out of the way.
  
  > **Comments:**
  > **username_0**: Thanks for responding, @username_1, I really appreciate it. Worked like a charm!  I ended up using 9 instead of 1 because the name with the spaces was still causing issues and I was unable to load the UI. Refreshed db, followed you directions and set everything to ID 9 instead. Worked like a dream and I was able to create a new generic case type.  Thank you, again.  Update: unfortunately, I don't have enough of a rep to upvote your answer but my feedback was recorded.  
  > **username_1**: Great, glad it worked out.  
  > **username_2**: add a couple of more comments here so we can upvote them (if they are nice comments)  
  
  ---
  
  