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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to get & set tags and custom data fields on an Individual
Pages: [1]

Author Topic: How to get & set tags and custom data fields on an Individual  (Read 2474 times)

kokorocreations

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
  • CiviCRM version: 4.5.2
  • CMS version: Drupal 7.32
  • MySQL version: 5.5.36-log
  • PHP version: 5.3.29
How to get & set tags and custom data fields on an Individual
March 30, 2008, 10:01:03 am
Hi

I really hope someone here can help me.  I cannot figure out how to get and set tags on an individual.  I also cannot figure out how to get and set custom data fields on an individual.

For example:  John Doe has contact_id of 2.  He is tagged with tags "Tag 1" and "Tag 2".  I can see this in the GUI.  Also, I have defined a custom field group named "My Fields" and in that group I have text fields "MyFIeld 1" and "MyFIeld 2"  (they show up in the GUI with spaces in their names). 

If I do a &civicrm_contact_get(), I do not get either the tags or the custom data fields.  How do I get them?

And then when I am creating a new user, how do I set them?

I'm sorry if this seems like a totally basic question.  This is my first time working with CiviCRM.  I have combed the documentation, wiki, forums, and google for what seems like hours and just cannot get there.

Thanks for your help!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to get & set tags and custom data fields on an Individual
March 30, 2008, 11:17:03 am

To get/set tags, check the functions in:

api/v2/EntityTag.php

You can specify which custom fields u want to retrieve in civicrm_contact_get, by adding them to the return properties (custom_ID)

In general our api's are not complete (IMO). You best bet might be to call the objects and methods directly

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

kokorocreations

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
  • CiviCRM version: 4.5.2
  • CMS version: Drupal 7.32
  • MySQL version: 5.5.36-log
  • PHP version: 5.3.29
Re: How to get & set tags and custom data fields on an Individual
April 01, 2008, 06:02:32 pm
Thank you very much Donald.

kokorocreations

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
  • CiviCRM version: 4.5.2
  • CMS version: Drupal 7.32
  • MySQL version: 5.5.36-log
  • PHP version: 5.3.29
Re: How to get & set tags and custom data fields on an Individual
April 01, 2008, 06:15:13 pm

I still seem to be stuck on how to set custom fields on a contact when I am adding the contact.

This is what my code looks like:

Quote
$params = array(
   "contact_type" => "Individual",
   "first_name" => $contact[$contactnum]["first"],
   "middle_name" => $contact[$contactnum]["middle"],
   "last_name" => $contact[$contactnum]["last"],
   "nick_name" => $contact[$contactnum]["preferred"],
   "job_title" => $contact[$contactnum]["title"],
   "home_URL" => $contact[$contactnum]["url"],
   "student__" => $contact[$contactnum]["studentid"],
   );

$addedContact = &civicrm_contact_add($params);

The field "student__" is "Student #" in the GUI and "student__" in the database. 

What's the right way to set custom fields for a contact?

Thanks so much

dougall

  • Guest
Re: How to get & set tags and custom data fields on an Individual
April 02, 2008, 04:50:28 am
I'm also trying to do this since I need to do an import of data into both standard and custom fields in civicrm from a different database, and then subsequently update standard and custom field values from outside civicrm.

I've also only just started with civicrm (so I'm not really sure) but I don't think you set the custom field values at the same time as creating the contact.

Currently there doesn't appear to be v2 API functions for setting custom field values, so (like lobo says) it's going to be necessary to call the civicrm objects/methods directly ... and having just started to use civicrm this is an initially somewhat daunting prospect.

I've been having a look at the civicrm 1.9 api (since this was more comprehensive) just to get an idea where to start, although I appreciate civicrm's db schema has changes, and how custom groups/fields/values are handled seems to have changed also.

I'll post here if i have any success, and I'd be interested to hear from you if you do!

...dougall
« Last Edit: April 02, 2008, 05:38:33 am by dougall »

Manish Zope

  • I’m new here
  • *
  • Posts: 18
  • Karma: 4
Re: How to get & set tags and custom data fields on an Individual
April 04, 2008, 07:12:17 am
Check this testcase
It uses Contact v2 API to set/get custom data of a Contact
http://svn.civicrm.org/civicrm/branches/v2.0/test-new/SimpleTest/api-v2/ContactAddWithCustomData.php

Please note that there was some bug with civicrm_contact_add($params) (due to which custom data was not set using this particular API)
It is fixed in r 13868

The changelog :
http://fisheye.civicrm.org/browse/CiviCRM/branches/v2.0/api/v2/Contact.php?r1=13681&r2=13868
http://fisheye.civicrm.org/browse/CiviCRM/branches/v2.0/api/v2/utils.php?r1=13584&r2=13868

HTH
Manish

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to get & set tags and custom data fields on an Individual

This forum was archived on 2017-11-26.