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) »
  • Activity Custom Fields, how to set using API/SOAP+API?
Pages: [1]

Author Topic: Activity Custom Fields, how to set using API/SOAP+API?  (Read 1601 times)

ijames

  • Guest
Activity Custom Fields, how to set using API/SOAP+API?
December 16, 2009, 01:23:12 pm
I'm starting this question as a new post...

I've setup the SoapServer.php to communicate with CiviCRM using the APIs.

It's all working pretty well, except for the custom fields on the activity.  When I try to set the custom fields, it was erroring out, on the SOAP until I noticed that it appears that custom fields for activities need three digits:

custom_XXX. 

I have been using custom_XX for custom fields on contact entities and that works.

I set my params custom_XXX and it doesn't error out anymore, but it doesn't seem to set the values on the custom fields.

In other words, I'm calling:

civicrm_activity_create()

With:

Array
(
    [activity_name] => Support
    [source_contact_id] => 810
    [target_contact_id] => 810
    [status_id] => 2
    [subject] => Endorsement - CFEA
    [details] =>
    [activity_date_time] => 20091201000000
    [duration_minutes] => 0
    [duration_hours] => 0
    [custom_020] => Entry Tool
    [custom_021] =>
    [custom_023] => 806
    [custom_022] => 20091216015205
    [custom_025] =>
)

Where custom 23 is a contact_id field and custom 22 is a date field.

But when I look in CiviCRM, the custom fields are not set.

The operation is returning:

Array
(
    [is_error] => 0
    [id] => 699
    [source_contact_id] => 810
    [source_record_id] =>
    [activity_type_id] => 27
    [subject] => Endorsement - CFEA
    [activity_date_time] => 20091201000000
    [duration] =>
    [location] =>
    [phone_id] =>
    [phone_number] =>
    [details] => null
    [status_id] => 2
    [priority_id] => 2
    [parent_id] =>
    [is_test] =>
    [medium_id] =>
    [is_auto] =>
    [relationship_id] =>
    [is_current_revision] =>
    [original_id] =>
    [is_deleted] =>
)


Question:  Can I set custom fields on activities?  How?  What am I doing wrong?

Thanks!



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: Activity Custom Fields, how to set using API/SOAP+API?
December 16, 2009, 08:04:09 pm

1. we recommend you use the REST API rather than the SOAP API. We've migrated to REST over the past few releases

2. there is no east way to store custom fields via the API for activites (or some other non contact objects in general). I dont think we've coded this very well and should recode how we store value and custom values for all top level objects

3. for now, your best bet would be to expose the function: CRM/Core/BAO/CustomValueTable.php, function setValues as an API call and use that to set custom values

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

ijames

  • Guest
Re: Activity Custom Fields, how to set using API/SOAP+API?
December 18, 2009, 12:40:39 am
Lobo, thanks very much! 

I've been eyeing the REST but didn't jump in.  Is there a reason to make the switch at this time?  Are there any PHP examples out there? 

Is modifying the REST file the same as modifying the SoapServer.php file?

James

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Activity Custom Fields, how to set using API/SOAP+API?

This forum was archived on 2017-11-26.