Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. civicrm_api3('contact', 'create', ['id'=>123, 'gender'=>'Male'])
  2.  
  3. function getIdforLabel($entity, $field, $label) {
  4.  
  5. $result = civicrm_api3($entity, 'getoptions', ['sequential' => 1, 'field' => $field]);
  6. if ($result['is_error']) {
  7. throw new Exception("Failed to getoptions for $entity.$field");
  8. }
  9. foreach ($result['values'] as $result) {
  10. if ($result['value'] == $label) {
  11. return $result['key'];
  12. }
  13. }
  14. throw new Exception("Supplied value, '$label' is not a valid option.");
  15. }
  16.  
  17. $gender_id = getIdForLabel('contact', 'gender_id', 'Male');
  18. civicrm_api3('contact', 'create', ['id'=>$contact_id, 'gender_id'=>$gender_id]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement