1

I'm trying to import a set of Multi Select Options on a Custom Field that's attached to Activities, but I can't find a way to do it.

I've tried replacing the csv field with the label strings, the values, comma separating both of these, space separating them and quoting them (with all of the above) but cannot get the multi select options to import.

I've moved on to the API - but can't find how to pull (or set) customValue fields for activities.

Finally - Mysql. I can insert a created string directly by placing the values into the civicrm_value_xxx_id table against the entity_id (activity id), separated by . CHAR(01) . statements, as in (for a single 'test' line on a local install):

UPDATE civicrm_value_activity_opti_4 
SET option_group_field_7 = CONCAT(CHAR(01), '1', CHAR(01) , '10', CHAR(01), '100', CHAR(01)) 
WHERE entity_id = 625;

...but this seems laborious and like there should be a more simple way to insert multiple selected options into an activity custom field (as it's going to require a bit of scripting to pick up the details of each of the (30000?) activities.

Does anyone here know what I'm missing, or if there is a more straightforward way to import the multi-select options?

4
  • 1
    did you try with values instead of labels? Jan 25, 2022 at 17:06
  • 1
    I did indeed, but had no joy :(
    – Marsh
    Jan 25, 2022 at 20:24
  • 1
    did you try the patch below? Jan 25, 2022 at 21:21
  • I did. It was magnificent. Thank you :)
    – Marsh
    Jan 27, 2022 at 20:28

1 Answer 1

3

Its a known issue in CiviCRM and is logged at https://lab.civicrm.org/dev/core/-/issues/2706

Also CSV import extension don't support this(https://github.com/eileenmcnaughton/nz.co.fuzion.csvimport/issues/32).

You can apply the below patch to work

diff --git a/CRM/Activity/Import/Parser/Activity.php b/CRM/Activity/Import/Parser/Activity.php
index a1d3cdfa8b..3373ceabbc 100644
--- a/CRM/Activity/Import/Parser/Activity.php
+++ b/CRM/Activity/Import/Parser/Activity.php
@@ -177,6 +177,11 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
         elseif (!empty($customFields[$customFieldID]) && $customFields[$customFieldID]['data_type'] == 'Boolean') {
           $params[$key] = CRM_Utils_String::strtoboolstr($val);
         }
+        elseif (!empty($customFields[$customFieldID]) && $customFields[$customFieldID]['serialize'] == TRUE) {
+          $val = trim($val);
+          $val = str_replace('|', ',', $val);
+          $params[$key] = explode(',', $val);
+        }
       }
       elseif ($key === 'activity_date_time') {
         $params[$key] = CRM_Utils_Date::formatDate($val, $dateType);
1
  • That's perfect - thanks Pradeep - I can now import multiple options in an options group attached to activities.
    – Marsh
    Jan 26, 2022 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.