CiviCRM Asked on December 17, 2020
I am trying to import records to a custom multi-record set of fields.
I read somewhere that it was a new feature for 4.5.8 but now for the life of me I cannot find where I read it – pretty sure it was the release notes, but may have got the version wrong.
Would appreciate a pointer in the right direction. (we are currently on 4.6.4)
Many thanks
Steps:
You should see the multi-record field to import
Correct answer by Sanjay Jain on December 17, 2020
I ended up using a drush script to import data into custom multi record fields:
create file import-script.scr
run it as: drush scr import-script.scr
script:
<?php
$file = '/var/www/html/sites/default/scripts/civicrm_value_import.csv';
$fh = fopen($file, 'r');
while ($row = fgetcsv($fh)) {
$contact_id = $row[8];
if (empty($contact_id)) {
continue;
}
// Build array for new data
$import = [
'entity_id' => $contact_id,
'discharge_reason_329' => $row[14],
'primary_presenting_problem_335' => $row[15],
'principal_diagnosis_336' => $row[16],
'diagnosis_2_337' => $row[17],
'diagnosis_3_338' => $row[18],
'opioid_dependency_339' => $row[19]
];
if (!empty($row[11])) {
$import += ['referral_date_331' => $row[11]];
}
if (!empty($row[12])) {
$import += ['enrolment_date_332' => $row[12]];
}
if (!empty($row[13])) {
$import += ['discharge_date_333' => $row[13]];
}
if (!empty($row[21])) {
$import += ['initiation_date_341' => $row[21]];
}
// print_r([$import]);
// Insert
db_insert('civicrm_value_raam_66')
->fields($import)
->execute();
// For testing one row
// break;
}
Answered by KarinG - Semper IT on December 17, 2020
If you have complicated import needs - for instance, you need to import multi-value custom fields as part of a larger import - you may want to consider the "Advanced Import-Form Processor" approach.
I really need to write docs up, but in general:
Advanced Import gives you an import UI; Advanced Import Form Processor lets you use a Form Processor instance to process each line in your file. Advanced Import has some limitations (e.g. it doesn't handle large files well) and Form Processor is relatively slow - but you can create pretty much any import you need without coding by using these three extensions together. And it has an end-user focused UI. Much like Views or Webform, an admin can create something complex, but the end result is usable by end users.
Below is a screenshot of a Form Processor instance I created. I was given a list of students with their schools and related information. I was able to:
Answered by Jon G - Megaphone Tech on December 17, 2020
You can import multi-value custom fields through the API, including the API CSV Import GUI. You use the CustomValue
API; you can also use the command-line CSV import tool or even drush
.
Your contact ID field should be imported as entity_id
. If the custom field ID is "4", then import to custom_4
.
As an example - if your field set is called "schools attended", with custom fields "school" (custom field ID 7) and "degree" (custom field ID 8) for a contact with an ID of 123, your data may look like this:
entity_id | custom_7 | custom_8
123 | University of Wisconsin | BA
123 | Rutgers University | MA
Answered by Jon G - Megaphone Tech on December 17, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP