CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Viewing group custom fields
Pages: [1]

Author Topic: Viewing group custom fields  (Read 2110 times)

LindseyM

  • I post frequently
  • ***
  • Posts: 229
  • Karma: 8
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3.6
Viewing group custom fields
June 22, 2012, 04:05:01 am
We have some group custom fields which are Data type: Contact reference and Field type: Autocomplete Select. There are several fields in the set, listing group leaders, administrators, hosts etc

I would like to be able to create a view or export which shows these fields for numerous groups at once.  Ideally I want to specify which groups I see using the Group Type filter.  A friend has attempted to do this using the api generator and said he could get the fact that the custom field existed but couldn't retrieve any actual data.

Is this somehting we can achieve without coding?  Any tips on the best way forward gratefully received.  Thanks.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Viewing group custom fields
June 24, 2012, 05:34:02 am
What did you try to do with the API exactly? You should be able to get data for the custom fields using the API...but that would still involve a little coding?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: Viewing group custom fields
August 16, 2012, 04:02:33 pm
Ok, so I was taking a look at what LindseyM's friend was trying to do; and it boils down to this api call:

$groups = civicrm_api('Group', 'Get', array('is_hidden' => 0, 'version' => 3, 'return.custom_206' => 1));

This returns the error 'DB Error: no such field' when called. It seems the api code doesn't have the necessary plumbing to load the custom fields..

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Viewing group custom fields
August 17, 2012, 02:53:46 am
Try this:
$groups = civicrm_api('Group', 'Get', array('is_hidden' => 0, 'version' => 3, 'return = 'custom_206'));

Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Viewing group custom fields
August 19, 2012, 07:10:51 am
I think what you want is
civicrm_api('custom_value', 'get', array('version' => 3, 'return.custom_206' => 1));
Try asking your question on the new CiviCRM help site.

LindseyM

  • I post frequently
  • ***
  • Posts: 229
  • Karma: 8
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3.6
Re: Viewing group custom fields
August 19, 2012, 09:52:43 am
Thanks for your input.  jcasharpe has resolved it and we now have a view which shows these fields with a direct link enabling us to alter them as well.  I'm not sure which route he used but it has been successful!

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: Viewing group custom fields
November 17, 2012, 05:20:43 am
I'd worked around this in the previous case by directly doing an SQL query.  I've now run into this again so am trying via the API but am failing to get anything to work with 4.1. I've not tried on 4.2.

Quote from: Erik Hommel on August 17, 2012, 02:53:46 am
Try this:
$groups = civicrm_api('Group', 'Get', array('is_hidden' => 0, 'version' => 3, 'return = 'custom_206'));
This doesn't seem to work, it returns just the regular group information.

Quote from: Coleman Watts on August 19, 2012, 07:10:51 am
I think what you want is
civicrm_api('custom_value', 'get', array('version' => 3, 'return.custom_206' => 1));
This requires an entity_id to be set which I believe only refers to contacts and not groups?

Looking at the api logic it seems that there is no consideration for the custom fields in the CRM_Contact_BAO_Group class that the api calls through to.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Viewing group custom fields
November 17, 2012, 05:40:45 am
The custom values can apply to several entities (Contact, Event, Activity etc.) and I think it should also work for groups? You will need to provide the group_id of the group you are looking for
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: Viewing group custom fields
November 17, 2012, 06:11:05 am
It doesn't seem to work via the Group Get api. The custom values api wants an entity_id, which as far as I can make out is a contact_id, unless theres some mapping between group_id and entity_id's that I'm missing?

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Viewing group custom fields
November 17, 2012, 06:22:46 am
I assume your data field custom_206 is in a Custom Data Set extending Groups. If this is the case, I would expect the entity_id in the custom_value api to hold the id of the group the custom data field is linked to. This is the same behaviour as for a contact if you are creating a Custom Data Set extending Contacts?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: Viewing group custom fields
November 17, 2012, 09:53:54 am
Hmm it seems slightly broken:

/civicrm/ajax/rest?json=1&sequential=1&debug=1&&entity=CustomValue&action=get&entity_id=6
Gives output:
{
   "is_error":1,
   "error_message":"No values found for the specified entity ID and custom field(s)."
}

whereas:
/civicrm/ajax/rest?json=1&sequential=1&debug=1&&entity=CustomValue&action=get&entity_id=6&return.custom_206=1

gives:
{
   "is_error":0,
   "undefined_fields":["return_custom_206"],
   "version":3,
   "count":1,
   "id":206,
   "values":[{
      "entity_id":"6",
      "latest":"16202",
      "id":"206",
      "0":"16202"
   }]
}

which gives the correct values but something is clearly broken as it returns 'undefined_fields' set. I'd expect to get all values out if I don't explicitly set a return values, and for undefined_fields not to be set in the above case.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Viewing group custom fields
November 18, 2012, 06:01:20 am
I agree :-) Could you find time to fix it and commit the patch? That would be awesome!
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Viewing group custom fields

This forum was archived on 2017-11-26.