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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Adding Custom Data To Contacts
Pages: [1]

Author Topic: Adding Custom Data To Contacts  (Read 1131 times)

spork

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.0.1
  • CMS version: Drupal 7
Adding Custom Data To Contacts
January 20, 2011, 09:57:55 am
Sorry if this is an obvious problem, but I am having difficulty finding a way to add custom data to a contact through the public API. The custom data public API seems to be only for defining the custom data structure and the contact public API can retrieve custom fields for a contact but it doesn't seem to mention anything about setting them.

I've been digging in the database seeing how CiviCRM stores custom data (in a civicrm_value_<customgroupname>_<customgroupid> table) but I figure there's probably an internal API function that I'd be better off using...


Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Adding Custom Data To Contacts
January 20, 2011, 10:32:12 am
You can pass custom data into the create functions - I just added an example. You can also pass it into contact_update (in api v3 we will only use update not create & the presense of contact_id will determine update vs add but not quite sure whether contact_create works like that in v2 - I think it does)

http://wiki.civicrm.org/confluence/display/CRMDOC33/Contact+APIs#ContactAPIs-civicrmcontactcreate%28%26%24params%29
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

spork

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.0.1
  • CMS version: Drupal 7
Re: Adding Custom Data To Contacts
January 20, 2011, 11:30:51 am
Okay, nice. From the civicrm_contact_update example it looks like I can just add 'custom_<fieldid>' => <customdata> to $params... though I'm thinking there might be an issue in the future since I there's a good chance we will be modeling some of our data using multirecord custom groups.

Thanks
spork

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Adding Custom Data To Contacts
January 20, 2011, 12:04:52 pm
So, in the latest version (not sure whether 3.3.x or 3.4) there is a patch that allows you to do multi-field by id e.g

custom_12_23 ="blah"

But as at current (or before the patch)

custom_12 ="blah"

is all that's accepted & it adds an entry to the multi-field set rather than updating
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Adding Custom Data To Contacts
January 20, 2011, 02:56:55 pm
Hi,

You might need to dig into how the multiple records custom set is saved from the web interface, and I'm guessing you will have to implement the API for that case.

Not super complicated, but you'll need to find your way on the code base.

(haven't looked, but haven't heard of someone using the API like you intend to).

Good luck

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Adding Custom Data To Contacts
January 20, 2011, 03:00:49 pm
Xavier - the bit I was refering to is api behaviour in 3.4 by virtue of a core patch having been applied (I've tested the patch on 3.2.5 & it works to give the same behaviour)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Adding Custom Data To Contacts
January 20, 2011, 03:30:14 pm
So it does mean that 23 is the 23th "copy" of the custom field 12 ?

Quote from: Eileen on January 20, 2011, 12:04:52 pm
custom_12_23 ="blah"
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Adding Custom Data To Contacts
January 20, 2011, 03:53:53 pm
almost 23 is the field id in the relevant custom data table
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Adding Custom Data To Contacts
January 20, 2011, 04:18:48 pm
and 12?

Quote from: Eileen on January 20, 2011, 03:53:53 pm
almost 23 is the field id in the relevant custom data table
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Adding Custom Data To Contacts
January 20, 2011, 04:29:02 pm
So, my custom field is

electorate_248

and there is a field 'id'

so custom_248_52 is the same as

UPDATE civicrm_value_electorates_1 SET electorate_248 = "blach" WHERE id = 52
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Adding Custom Data To Contacts

This forum was archived on 2017-11-26.