Answers.Body: <p>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:</p>
  
  <p>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 <code>settings.php</code> file.</p>
  
  <p>See <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Views3+Integration" rel="nofollow noreferrer">http://wiki.civicrm.org/confluence/display/CRMDOC/Views3+Integration</a> for details.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-20T10:00:19.173Z
Answers.Text: yes, did that, see a previous comment. it still uses `civicrm_contact.custom_3`
Answers.UserDisplayName: commonpike
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-08T07:05:08.557Z
Answers.Text: Hey everyone. How does this work in a single CiviCRM Drupal Database. I understand adding the table is if the databases are different?
Answers.UserDisplayName: Sohal Khatwani
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-09T14:16:00.000Z
Answers.Text: Right, edited the answer to be more clear.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-12T00:12:30.017Z
Answers.Text: 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?
Answers.UserDisplayName: Sohal Khatwani
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-30T00:36:09.430Z
Answers.Text: 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.
Answers.UserDisplayName: Sohal Khatwani
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-20T01:46:04.780Z
Answers.LastActivityDate: 2016-12-09T14:15:50.753Z
Answers.LastEditDate: 2016-12-09T14:15:50.753Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>You have to add a map of the civicrm tables to Drupal's settings.php for that to work. See <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Views3+Integration" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/Views3+Integration</a> for details. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-12T19:39:46.380Z
Answers.Text: 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 ?
Answers.UserDisplayName: commonpike
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-12T19:48:11.613Z
Answers.Text: 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.
Answers.UserDisplayName: Jeremy Proffitt
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-12T20:01:56.390Z
Answers.Text: 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`.',
Answers.UserDisplayName: jackrabbithanna
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-12T21:33:01.493Z
Answers.Text: @jackrabbithanna is the custom field supposed to be in civicrm_contact.custom_2 column ? I dont have that column ?
Answers.UserDisplayName: commonpike
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-12T23:33:59.627Z
Answers.Text: 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
Answers.UserDisplayName: jackrabbithanna
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-21T16:32:45.623Z
Answers.Text: @jeremy its a boolean field
Answers.UserDisplayName: commonpike
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-21T16:56:05.783Z
Answers.Text: @jackrabbithanna .. none that I know of. I have civicrm, civicrm_entity and webform_civicrm ..
Answers.UserDisplayName: commonpike
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-12T19:01:14.953Z
Answers.LastActivityDate: 2015-04-12T19:01:14.953Z
Answers.UserDisplayName: Jeremy Proffitt
Answers.Body: <p>Saw the same issue here.</p>
  
  <p>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.</p>
  
  <p>When we selected it as CiviCRM Custom: My Field, it worked.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-13T19:40:22.277Z
Answers.Text: WOW ! That is .. THANKS ! Same here. How could I have missed that ! Accepting your answer.
Answers.UserDisplayName: commonpike
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-13T15:47:03.000Z
Answers.LastActivityDate: 2015-10-13T15:47:03.000Z
Answers.UserDisplayName: davejenx
Body: <p>[EDIT] Totally editing this question. Custom fields do not work in my Drupal views, at all:</p>
  
  <p><img src="https://i.sstatic.net/kE2ZH.png" alt="enter image description here"></p>
  
  <p>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. </p>
  
  <p>What could be causing this ? I need a solution pretty urgent :-|</p>
  
  <p>PS. I did map the values in settings.php, and this in general seems to work. One of the entries is <code>'civicrm_value_[PRIVATE_PARTS_HIDDEN]_1'  =&gt; '[MY_CIVIDB_NAME_HERE].',</code></p>
  
  <p>PPS. The checkbox used to add the field to the list, in the html source, reads</p>
  
  <pre><code>&lt;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"&gt;
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-12T19:00:22.233Z
Comments.Text: Powered by CiviCRM 4.5.3,
Comments.UserDisplayName: commonpike
Tags: <custom-fields><sql><drupal-views>
Title: How do I use custom fields in Drupal views?
ThreadText: # How do I use custom fields in Drupal views?
  
  (Asked by: username_0 on 2015-04-12)
  
  [EDIT] Totally editing this question. Custom fields do not work in my Drupal views, at all:
  
  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
  
  **Tags:** custom-fields, sql, drupal-views
  
  > **Comments:**
  > **username_0**: Powered by CiviCRM 4.5.3,  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_5 on 2015-10-13. Score: 7 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_0**: WOW ! That is .. THANKS ! Same here. How could I have missed that ! Accepting your answer.  
  
  ---
  
  ### Answer by username_1 on 2015-05-20. Score: 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.
  
  > **Comments:**
  > **username_0**: yes, did that, see a previous comment. it still uses `civicrm_contact.custom_3`  
  > **username_2**: Hey everyone. How does this work in a single CiviCRM Drupal Database. I understand adding the table is if the databases are different?  
  > **username_1**: Right, edited the answer to be more clear.  
  > **username_2**: Hi @username_1. 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?  
  > **username_2**: 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.  
  
  ---
  
  ### Answer by username_3 on 2015-04-12. Score: 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.
  
  > **Comments:**
  > **username_0**: 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 ?  
  > **username_3**: 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.  
  > **username_4**: 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`.',  
  > **username_0**: @username_4 is the custom field supposed to be in civicrm_contact.custom_2 column ? I dont have that column ?  
  > **username_4**: 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  
  > **username_0**: @jeremy its a boolean field  
  > **username_0**: @username_4 .. none that I know of. I have civicrm, civicrm_entity and webform_civicrm ..  
  
  ---
  
  