Skip to content

Custom field using option group returns incorrect values when option values are non-numeric

Custom field using option group returns incorrect values when option values are non-numeric.

See org.civicoop.action-provider/Civi/ActionProvider/Action/AbstractGetSingleAction.php

This function returns 0,1,2 for the field when non-numeric values have been saved as multiple options. For example when a option group has both labels and values like: Option X, Option Y, Option Z

  protected function convertCustomFieldWithMultipleValues($value) {
    foreach($value as $k=>$v) {
      if ($k == 0 && $v >= 1) {
        return $value;
      }
    }
    return array_keys($value);
  }

With a small change as shown below, this function then returns the correct values: Option X, Option Y, Option Z for the field.

  protected function convertCustomFieldWithMultipleValues($value) {
        return $value;
  }

I am not sure why this function was required, perhaps it is/was required to workaround a different issue or CiviCRM API bug.

Option group - note that Option X, Option Y, Option Z are both the label and the value. Other options have numeric values

image

Test Activity record with custom field, option values selected

image

Before this patch the Form processor loads the correct values from the Activity record, Field A but the incorrect values for Field B - eek!

image

With this patch the Form processor now loads the correct values from the Activity record, Field A and Field B

image

Agileware Ref: CIVICRM-2067

Edited by justinfreeman (Agileware)

Merge request reports