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) »
  • problem with updating preferred_communication_method using API
Pages: [1]

Author Topic: problem with updating preferred_communication_method using API  (Read 1417 times)

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
problem with updating preferred_communication_method using API
October 21, 2011, 10:42:54 am
I'm trying to update an individual's preferred communication method using civicrm_api( 'contact','update',$params )

the $params array is set up as

$params = array(
      'id' => $contact_id,
      'preferred_communication_method' => $preferred_communication_method,
      'contact_type' => 'Individual',
      'version' => 3,
);

print_r of $preferred_communication_method gives

Array (
  • => 1 [1] => 2 [2] => 3 [3] => 4 )


even print_r of $params shows it correctly, but. After the update the preferred communication method has been set to

Array (
  • => 0 [1] => 1 [2] => 2 [3] => 3 )


What am I doing wrong?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: problem with updating preferred_communication_method using API
October 23, 2011, 04:55:28 pm
Did create do anything any different to update (update just does 'get' + 'create' & we don't really recommend it - we implemented it to deal with situations where 'create' doesn't work right but our focus is on fixing create & many of the original bugs have been ironed out in that regard).
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

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: problem with updating preferred_communication_method using API
October 24, 2011, 11:56:12 pm
Not tried create - do I have to do a delete first?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: problem with updating preferred_communication_method using API
October 25, 2011, 12:03:16 pm
You probably don't need to - if you pass in the $param['id'] you should be able to update the existing one.
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

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: problem with updating preferred_communication_method using API
October 28, 2011, 12:31:41 am
Create doesn't work either - same problem :(

zinbads

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
  • CiviCRM version: 3.4
  • CMS version: Drupal
  • MySQL version: 5.1.45
  • PHP version: 5.2.8
Re: problem with updating preferred_communication_method using API
October 28, 2011, 03:20:16 am
me too.........

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: problem with updating preferred_communication_method using API
October 28, 2011, 03:32:26 am
Not sure, try to look at what the normal form does and see what's the format that is passed to the BAO (we need the same, obviously).

as an aside "0 [1] => 1 [2] => 2 [3] => 3 )" is a very unfriendly format for the API (both as input and output), would be great if you could add a conversion bit in api/v3/Contact.php to make it more readable

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: problem with updating preferred_communication_method using API
October 28, 2011, 06:38:34 pm
Interesting - I was looking at this yesterday & was going to post about it / use it as an example in our API discussion of what handling should be done where.

( in examples below I'm setting the value  . 3 for Postal)

DAO accepts
CRM_Core_DAO::VALUE_SEPARATOR . 3 . CRM_Core_DAO::VALUE_SEPARATOR
BAO accepts above + array('3'=> 1)
Import Parser Code Accepts 'Postal,Phone'
API accepts the formats supported by BAO & DAO

Nothing accepts '3' or array(3) which seem most intuitive.

I'm reluctant to add handling for this as a special case on the API. (ie. this is what we do for this specific field). We could denote fields that store data in a custom separator parsed format somehow in getfields (which I think means that in the medium term it will be stored in the xml).

Then either the API (short-term) or BAO (medium-term) can convert it.

This also raises the 'macro' idea - e.g. some similar fields support a string rather than a value. Probably the first step on this is to get a list of common types of format support which hopefully we'll do in the next few weeks.
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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: problem with updating preferred_communication_method using API
October 30, 2011, 05:50:40 pm
NB - adding this patch on the BAO would probably fix @ BAO level but it's a continuation of the hacky method of field handling.

Index: CRM/Contact/BAO/Contact.php
===================================================================
--- CRM/Contact/BAO/Contact.php   (revision 37037)
+++ CRM/Contact/BAO/Contact.php   (working copy)
@@ -156,6 +156,12 @@
             } else {
                 $contact->preferred_communication_method = '';
             }
+        }elseif(is_integer($prefComm)){
+
+                $prefComm =
+                    CRM_Core_DAO::VALUE_SEPARATOR .
+                    $prefComm .
+                    CRM_Core_DAO::VALUE_SEPARATOR;
         }
 
         $allNull = $contact->copyValues($params);
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

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: problem with updating preferred_communication_method using API
October 31, 2011, 02:25:26 am
Thanks. Not sure I enirely understand this, but I'll have a look later

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: problem with updating preferred_communication_method using API
October 31, 2011, 02:35:59 am
It's more about how Civi could be improved to support it. But you should be able to use this in your code too

elseif(is_integer($prefComm)){
+
+                $prefComm =
+                    CRM_Core_DAO::VALUE_SEPARATOR .
+                    $prefComm .
+                    CRM_Core_DAO::VALUE_SEPARATOR;
         }
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) »
  • problem with updating preferred_communication_method using API

This forum was archived on 2017-11-26.