6

[EDIT] Totally editing this question. Custom fields do not work in my Drupal views, at all:

enter image description here

The interface to add the custom field worked just fine. It's only the generated sql thats wrong. Its refering to civicrm_contact.custom_3, but the value is actually stored in a related table called civicrm_value_[PRIVATE_PARTS_HIDDEN]_1.

What could be causing this ? I need a solution pretty urgent :-|

PS. I did map the values in settings.php, and this in general seems to work. One of the entries is 'civicrm_value_[PRIVATE_PARTS_HIDDEN]_1' => '[MY_CIVIDB_NAME_HERE].',

PPS. The checkbox used to add the field to the list, in the html source, reads

<input type="checkbox" id="edit-name-civicrm-contactcustom-3"    
name="name[civicrm_contact.custom_3]" 
value="civicrm_contact.custom_3" 
class="form-checkbox viewsImplicitFormSubmission-processed">
1
  • Powered by CiviCRM 4.5.3,
    – commonpike
    Apr 12, 2015 at 19:00

3 Answers 3

7

Saw the same issue here.

We noticed that the field appeared twice in the list of fields. We'd selected it as CiviCRM Contact: My Field - but it also appeared as CiviCRM Custom: My Field.

When we selected it as CiviCRM Custom: My Field, it worked.

1
  • WOW ! That is .. THANKS ! Same here. How could I have missed that ! Accepting your answer.
    – commonpike
    Oct 13, 2015 at 19:40
3

You have to add a map of the civicrm tables to Drupal's settings.php for that to work. See http://wiki.civicrm.org/confluence/display/CRMDOC/Views3+Integration for details.

7
  • I did that, otherwise I wouldnt be able to use views with civicrm at all i think ? an example line is 'civicrm_value_import_fields_3' => 'iaf_civicrm.', .. it doesnt specify which table the custom fields are in ?
    – commonpike
    Apr 12, 2015 at 19:39
  • 1
    If you copied the most recent output after copying and pasting from the admin page refunded in the wiki, that should do it. What type of custom field is it? A multiple record set field might have issues. Apr 12, 2015 at 19:48
  • 1
    The field values are in the tables such as the one you mentioned above although you need to wrap the table name in the ` symbol (to the left of the 1 key) such as: 'civicrm_value_import_fields_3' => 'iaf_civicrm.', Apr 12, 2015 at 20:01
  • @jackrabbithanna is the custom field supposed to be in civicrm_contact.custom_2 column ? I dont have that column ?
    – commonpike
    Apr 12, 2015 at 21:33
  • 1
    the custom_2 column shouldn't be in the civicrm_contact table, something strange is going on....I tested contextual filters with contact custom fields on 4.5.0 and it was working fine on my testbed....do you have any custom modules that would modify the View's field/filter handlers? Do you have a duplicate field in views somewhere for the field you are trying to use, it should be called CiviCRM [name of field-set]:[name of field] when you select it in the Views UI Apr 12, 2015 at 23:33
3

If drupal and civicrm are sharing a database, then this will work without any further configuration. But if you have civicrm in a separate database, there is an extra step:

Every time you create a custom field in CiviCRM it adds a new table to the database. You have to tell Views about the new table by adding the new line to your settings.php file.

See http://wiki.civicrm.org/confluence/display/CRMDOC/Views3+Integration for details.

5
  • yes, did that, see a previous comment. it still uses civicrm_contact.custom_3
    – commonpike
    May 20, 2015 at 10:00
  • Hey everyone. How does this work in a single CiviCRM Drupal Database. I understand adding the table is if the databases are different? Dec 8, 2016 at 7:05
  • Right, edited the answer to be more clear.
    – Coleman
    Dec 9, 2016 at 14:16
  • Hi @Coleman. I see you edited the answer. However, I am not sure this is accurate. I am still getting the error of SQLSTATE[42S22]: Column not found: 1054 Unknown column 'civicrm_case.custom_27' in 'field list' when trying to add a custom field to the view. Am I missing something? Dec 12, 2016 at 0:12
  • I did further testing and it seems like the custom fields work for certain types of views. For example, if i use a custom field for All Contact Types then it works correctly and even the dropdown shows CiviCRM:Custom - Field name. However, for a custom field for Cases it does not work and has the same issue i.e. refers to SQLSTATE[42S22]: Column not found: 1054 Unknown column 'civicrm_case.custom_3' in 'field list' - Any help would be appreciated. Dec 30, 2016 at 0:36

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.