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) »
  • civicrm_activity_update with custom data?
Pages: [1]

Author Topic: civicrm_activity_update with custom data?  (Read 1490 times)

Singularo

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
civicrm_activity_update with custom data?
July 27, 2008, 09:38:04 pm
Hello all,

This function doesn't appear to be updating the custom data for me, despite not throwing errors.

Should it work in v2.x?

Debugging through when submitting shows CiviCRM itself doesn't appear to use this function, and it almost looks like we should be using CRM_Activity_BAO_Activity::create directly and it doing like contact does and updating if there is an id, but I'm not sure.

Can someone clarify what is the correct way to update custom data with CiviCRM 2/

TIA

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: civicrm_activity_update with custom data?
July 27, 2008, 11:36:36 pm

check: http://forum.civicrm.org/index.php/topic,4104.msg18007.html#msg18007

I'm 99% sure your issue is exactly the same. Do you want to backport the patch to 2.0 and see if it works for you. Please update this topic if so

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

Singularo

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
Re: civicrm_activity_update with custom data?
July 28, 2008, 07:19:40 pm
Hmm I dont think thats it.

I was updating a date, but i've changed that to updating a numeric field, and still have the same issue.

The patches referenced seem to be about dates & contacts, and converting them using the mysql function, but i'm only updating an activity and not necessarily a date.

The code is (with hardcoded values until it works):

Code: [Select]
    $activity['contact_id'] = $form_values['uid'];
    $activity['id'] = $form_values['appid'];
    $activity['activity_type_id'] = 10;
    $activity['activity_date_time'] = date('YmdHis');

    // Update end date
    //$activity['custom_10'] = '20081007';

    // Update amount owing
    $activity['custom_9'] = '10000';

    // Start -- Lifted straight from CiviCRM
    $custom_data = array( );

    foreach ( $activity as $key => $value ) {
      if ($custom_field_id = CRM_Core_BAO_CustomField::getKeyID($key)) {
        CRM_Core_BAO_CustomField::formatCustomField( $custom_field_id, $custom_data, $value, 'Activity', NULL, $form_values['appid']);
      }
    }

    if (! empty($custom_data) ) {
      $activity['custom'] = $custom_data;
    }

    require_once('api/v2/Activity.php');
    $activity = civicrm_activity_update($activity);

Any other ideas?

Singularo

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
Re: civicrm_activity_update with custom data?
July 28, 2008, 08:43:02 pm
Fixed it a different way, calling the CustomValueTable::store directly
Code: [Select]
    $activity['custom_9'] = '10000';

    // Start -- Lifted straight from CiviCRM
    $custom_data = array( );

    foreach ( $activity as $key => $value ) {
      if ($custom_field_id = CRM_Core_BAO_CustomField::getKeyID($key)) {
        CRM_Core_BAO_CustomField::formatCustomField( $custom_field_id, $custom_data, $value, 'Activity', NULL, $form_values['appid']);
      }
    }

    if (! empty($custom_data) ) {
      $activity['custom'] = $custom_data;
    }

    require_once 'CRM/Core/BAO/CustomValueTable.php';
    CRM_Core_BAO_CustomValueTable::store( $custom_data, 'civicrm_activity', $form_values['appid'] );

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: civicrm_activity_update with custom data?
July 28, 2008, 10:40:26 pm

I tested the following code on trunk (2.1)

Code: [Select]
<?php

$params 
= array( 'source_contact_id' => 102,
                 
'target_contact_id' => 102,
                 
'assignee_contact_id' => 102,
                 
'activity_type_id' => 1,
                 
'subject' => 'Foo Bar',
                 
'activity_date_time' => '20030120000000',
                 
'custom_3'   => 'foo',
                 
'custom_4'     => '20030120000000' );

require_once 
'../civicrm.config.php';
require_once 
'api/v2/Activity.php';
$result = civicrm_activity_create( $params );
CRM_Core_Error::debug( 'r', $result );


It worked as expected (3 is a text field and 4 is a date field)

I also tested it with 2.0 and unforunately it did not work :(. Since you have a workaround, i'll avoid trying to figure out why it does not work in 2.0. I suspect the issue which i mentioned previously also affects the code. There might be a few other bugs in 2.0 with this also

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • civicrm_activity_update with custom data?

This forum was archived on 2017-11-26.