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) »
  • Hook for adding Custom Field Value
Pages: [1]

Author Topic: Hook for adding Custom Field Value  (Read 484 times)

jschenck

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.4.3
  • CMS version: 7
  • MySQL version: 5.5.34
  • PHP version: 5.4.9
Hook for adding Custom Field Value
December 13, 2013, 03:42:36 am
Hey
i new to civi and actually in a setup process for a small organisation in Germany.
I have two things i would like to approach and i think hooks can do it. But i need a start to put it together.

1. I would like to add another id to a contact. This ID should be put together out of the CiviID and another ongoing number. For Exampke CiviID+0000 The best would be to have also a button to raise this id by 1. For Example to have then: CiviID+0001

2. I would like to have Checkbox at a contact dataset, which is set when the contact got a membership of a specific type.

I followed the Hooks Instruction in the Wiki, and have a functioning hook. Looks Like that:

Code: [Select]
<?php

function myhooks_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
    
# configuration stuff
    
$customId = 25;

    if (
$objectName == 'Individual' && $op == 'create') {
        
# generate the login
        
$CiviID = $objectRef->id;
        
$NumBer = "0001";
        
$mandateRef = ($CiviID.$NumBer);

        
# assign to the custom field
        
$customParams = array("entityID" => $objectId,
            
"custom_$customId" => $mandateRef);
        require_once 
'CRM/Core/BAO/CustomValueTable.php';
        
CRM_Core_BAO_CustomValueTable::setValues( $customParams );
    }
} 
Problems are now:
1. for $NumBer i would like to use the value of a custom field. How do i do that.
2. this hooks creates a second dataset of this set of custom fields. So when i look at the contact i see two time the Set in which the custom field is. And the value filled in by the hook is in the second one.
3. I want to runs this hook not only while creating accounts, but also while editing accounts.
Thanks for your help.
Jan
« Last Edit: December 13, 2013, 04:57:11 am by jschenck »

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Hook for adding Custom Field Value
December 16, 2013, 12:27:44 am
Hi Jan,

you can use the CiviCRM API to retrieve a value of a custom field and set the value of a custom field. More information on the API can be found here:
http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API.
If you want to do the same for editing, you can do that with $op == 'edit'? Or do you mean you want to show the fields on the screen? If you have enabled the custom fields, they will show up in the standard CiviCRM form?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Hook for adding Custom Field Value

This forum was archived on 2017-11-26.