Answers.Body: <p>As far as your API call there goes...I don't see an 'id' => $row->price_field_id in there.  You'll need to query by id to get the value for each individual price field. I'm not exactly sure what the variable name on the object will be in your case...but the main thing is to query for the individual price fields data by id</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-10T23:31:50.123Z
Answers.LastActivityDate: 2017-07-10T23:31:50.123Z
Answers.UserDisplayName: jackrabbithanna
Body: <p>I am trying to use the Civi API within a Drupal view, in the global PHP field.</p>
  
  <p>It is all working, except for when I try to use an "Available Variable" from the view, it throws and error.  When I hard code the variable's value, it works, though.</p>
  
  <p>The variable I am using does contain the correct data; if I return just that variable, it returns the ID it should.</p>
  
  <p><strong>The code:</strong></p>
  
  <pre><code>civicrm_initialize();
  $start_date = civicrm_api3('price_field', 'getvalue', array(
    'return' =&gt; 'active_on',
    'price_set_id' =&gt; $row-&gt;price_set_id,
  ));
  
  return gettype($start_date);'
  </code></pre>
  
  <p><strong>Error</strong> 
  field active_on unset or not existing</p>
  
  <p>I am using Drupal 7 and CiviCRM 4.6.28.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-10T23:13:15.773Z
Comments.Text: you can access Price field data by installing CiviCRM Entity and its sub module CiviCRM Entity Views Extra
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-10T23:19:56.577Z
Comments.Text: I tried that...it's still not showing up in the view as a field.
Comments.UserDisplayName: Kimberlie Davis
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-10T23:27:35.153Z
Comments.Text: You have to add 2 Views relationships. 
  CiviCRM Price Set Entities: Price Set
  (Price Set) Price Field: Price Field
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-10T23:31:17.313Z
Comments.Text: You may need the Date Views module installed as well
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-10T23:37:03.043Z
Comments.Text: Okay, that worked.  Thank you very much for your help.  I'm still fairly new to Drupal, and views confuse me sometimes.  But, that makes  alot of sense now.
Comments.UserDisplayName: Kimberlie Davis
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-09T05:12:56.950Z
Comments.Text: sounds like the above should be the answer then. mark want to change yours and then Kimberlie can accept it?
Comments.UserDisplayName: petednz - fuzion
Tags: <api><drupal-views><php>
Title: Using CiviCRM API in Drupal View
ThreadText: # Using CiviCRM API in Drupal View
  
  (Asked by: username_0 on 2017-07-10)
  
  I am trying to use the Civi API within a Drupal view, in the global PHP field.
  It is all working, except for when I try to use an "Available Variable" from the view, it throws and error.  When I hard code the variable's value, it works, though.
  The variable I am using does contain the correct data; if I return just that variable, it returns the ID it should.
  The code:
  civicrm_initialize();
  $start_date = civicrm_api3('price_field', 'getvalue', array(
    'return' => 'active_on',
    'price_set_id' => $row->price_set_id,
  ));
  
  return gettype($start_date);'
  
  Error 
  field active_on unset or not existing
  I am using Drupal 7 and CiviCRM 4.6.28.
  
  **Tags:** api, drupal-views, php
  
  > **Comments:**
  > **username_1**: you can access Price field data by installing CiviCRM Entity and its sub module CiviCRM Entity Views Extra  
  > **username_0**: I tried that...it's still not showing up in the view as a field.  
  > **username_1**: You have to add 2 Views relationships.  CiviCRM Price Set Entities: Price Set (Price Set) Price Field: Price Field  
  > **username_1**: You may need the Date Views module installed as well  
  > **username_0**: Okay, that worked.  Thank you very much for your help.  I'm still fairly new to Drupal, and views confuse me sometimes.  But, that makes  alot of sense now.  
  > **username_2**: sounds like the above should be the answer then. mark want to change yours and then Kimberlie can accept it?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-07-10. Score: 1
  
  As far as your API call there goes...I don't see an 'id' => $row->price\_field\_id in there. You'll need to query by id to get the value for each individual price field. I'm not exactly sure what the variable name on the object will be in your case...but the main thing is to query for the individual price fields data by id
  
  
  ---
  
  