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) »
  • API to set "selected" for Custom Select Field Type
Pages: [1]

Author Topic: API to set "selected" for Custom Select Field Type  (Read 693 times)

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
API to set "selected" for Custom Select Field Type
February 14, 2013, 01:48:16 pm
I just wanted to post this. I searched the forums and couldn't find anything that made sense to me.

This allows me to edit the selected value for a custom "Select Field Type".

Here is the code that I am using...

Code: [Select]
   
if (!isset($config)) {
    require_once($_SERVER['DOCUMENT_ROOT'].
'/sites/default/civicrm.settings.php');
    require_once 'CRM/Core/Config.php';
    $config =CRM_Core_Config::singleton( );
}
require_once 'api/api.php';

$params = array( 'entity_id' => $cid, 'version' => 3,
      'custom_child_checkin:child_checkin_classroom' => array("value"=>$classroom), // classroom is the matching value for the select item that I want selected
  //'custom_105' => array("value"=>$classroom),
      );

  $results = civicrm_api('custom_value','create',$params);
  $results = (CRM_Core_BAO_CustomValueTable::setValues($params));

Hopefully someone finds this helpful!
« Last Edit: February 14, 2013, 01:50:11 pm by lee.gooding »

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API to set "selected" for Custom Select Field Type
February 14, 2013, 02:41:07 pm
Just a note

All this
Code: [Select]
if (!isset($config)) {
    require_once($_SERVER['DOCUMENT_ROOT'].
   '/sites/default/civicrm.settings.php');
    require_once 'CRM/Core/Config.php';
    $config =CRM_Core_Config::singleton( );
}
require_once 'api/api.php';

Should be done for you if you use

civicrm_initialize(TRUE);

(normally it's good practice to use the pattern

if(!civicrm_initialize(TRUE)){
  return;
}
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

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: API to set "selected" for Custom Select Field Type
February 18, 2013, 06:06:11 am
Thanks!

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: API to set "selected" for Custom Select Field Type
February 18, 2013, 06:31:25 am
I made this change in my scripts and now I get an error 500 (Failed to load resource: the server responded with a status of 500 (Internal Server Error) ) with my scripts. Any idea why this change would cause that?

Quote from: Eileen on February 14, 2013, 02:41:07 pm
Just a note

All this
Code: [Select]
if (!isset($config)) {
    require_once($_SERVER['DOCUMENT_ROOT'].
   '/sites/default/civicrm.settings.php');
    require_once 'CRM/Core/Config.php';
    $config =CRM_Core_Config::singleton( );
}
require_once 'api/api.php';

Should be done for you if you use

civicrm_initialize(TRUE);

(normally it's good practice to use the pattern

if(!civicrm_initialize(TRUE)){
  return;
}

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API to set "selected" for Custom Select Field Type
February 18, 2013, 11:33:00 am
No, I can't think of any reason
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) »
  • API to set "selected" for Custom Select Field Type

This forum was archived on 2017-11-26.