A client has many cases in spreadsheets, and Civicase looks very suitable. I cannot see any facility to import cases into Civi via the UI. Is this possible? I guess the alternative is to import directly into the database. Any suggestions?
4 Answers
You might look at the API cvs Importer extension. https://civicrm.org/extensions/api-csv-import-gui
I've found the extension extremely helpful for creating all kinds of CiviCRM data from CSV formatted data.
-
Don't know if we'll get the chance to use it ourselves, but thanks, that looks interesting.– DaveFFCommented Jun 8, 2016 at 8:29
-
I just used it recently to import a bunch of entries into option groups. Saved me a TON of data entry. Commented Jun 8, 2016 at 10:30
As far as I know there is no Import Cases in the UI. So importing into the database would be the solution, but make sure you respect all the data models! You need to add data to civicrm_case, civicrm_case_contact, probably civicrm_case_activity and civicrm_activity and for the roles into civicrm_relationship.
I've just bulk created a whole load of cases from activities, taking the subject, clients etc from the activity. Creating cases through the API works fine. Can post the code if anyone's interested.
-
Dave - am sure someone would appreciate that even if they aren't looking yet– petednz - fuzion ♦Commented Jun 8, 2016 at 8:48
-
1Sure, here it is: gist.github.com/davidknoll/8ad934d8736459c98e445f91576c719d (please note, this is not general as it contains IDs from our system)– DaveFFCommented Jun 8, 2016 at 9:16
I've been working out the queries to do this for the past week or so for a client who is migrating from an old desktop database.
Here's the full list of tables involved:
civicrm_case
civicrm_case_contact (to link each case to a contact id)
civicrm_activity (to create the necessary activities for each case)
civicrm_case_activity (links activity to case id)
civicrm_activity_contact (multiple records for each activity)
civicrm_relationship (relationships between case subject and assignees)
You can actually get away without filling in the relationships if this is purely historical data but it's only an extra query so you may as well fill it in.
I created a special case type for the data import and used the subject field to store details about the old cases during the SQL imports. I removed all required activities but one from this case type which simplified the import process.
When in doubt, just create test cases under a dummy contact and see what values are populated.
EDIT: I decided to write up the entire procedure on my website. You can find the details here - http://www.drewslair.com/2016/06/importing-case-data-civicase/
-
-1 for the fact it's really preferred to use an API call (or the API importer) rather than inserting directly into the SQL tables. API calls make sure that the relationships of data between and among the database tables is consistent. Inconsistent data can wreak havoc with upgrades. Commented Jun 8, 2016 at 10:29
-
That aside, it is an amazing write up that Andrew did– petednz - fuzion ♦Commented Sep 25, 2017 at 21:04