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) »
  • Particpant API Custom Data no set
Pages: [1]

Author Topic: Particpant API Custom Data no set  (Read 1025 times)

ceford

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Particpant API Custom Data no set
October 27, 2009, 04:34:22 pm
There are a few posts from about a year ago about custom data not being set and a problem identified in the cache. I have been trying to use the Participant API and have similar problems, and clearing civicrm_cache does not change anything. Reading the code, line 232 of CRM/Event/BAO/Participant.php tests for $params containing a 'custom' value that is an array. It doesn't because none of the examples that I have seen show a custom array, just fields. I have tried creating an array like this:

    $params = array(
                    'contact_id'    => $user_id,
                    'event_id'      => $camp,
                    'status_id'     => $status_count,
                    'role_id'       => 2,
                    'register_date' => "$date",
                    'source'        => 'Online Event Registration: API Testing',
                    'custom'        =>  array (
                    'application_number_38'   => $application_number,
                    'application_preference_number_39'  => $status_count,
                    'motivation_statement_40'   => 'Just Some Testing')
                    );
    $result = & civicrm_participant_create($params);

But that just produces a repeat of this error:

Warning: Invalid argument supplied for foreach() in /home/ceford/public_html/info/administrator/components/com_civicrm/civicrm/CRM/Core/BAO/CustomValueTable.php on line 284

To be honest I don't know if I am on the right track but with the wrong construction, or whether this custom data stuff is just plain broken. Any pointers would be appreciated.

Cliff

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: Particpant API Custom Data no set
October 27, 2009, 06:22:46 pm

I would use the participant api to create the record without the custom fields.

i would then use the the function setValues in CRM/Core/BAO/CustomValueTable.php to set the values of the various custom fields

the BAO function take a very specifically formatted custom array, hence u get those errors

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

ceford

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Re: Particpant API Custom Data no set
October 28, 2009, 02:17:28 am
I figured this out. There were two issues:

1. I did not realise that the custom data fields in the params array HAVE to be named custom_38 rather than application_number_38 (that is custom_xx rather than my_field_name_xx).

2. Custom note fields (textarea) get checked as a Memo data type in CRM_Core_BAO_CustomValueTable::setValues. That is not tested for so textarea data are not saved. I fixed this by adding case 'Memo': in the line below case 'String': in CRM/Utils/Type.php (lines 146/147). I hope that does not throw a spanner in the works elsewhere!

Fixing the latter did not fix the original problem - custom data are not saved with the civicrm_participant_create api call.

Cliff

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Particpant API Custom Data no set

This forum was archived on 2017-11-26.