In my drupal custom module I am creating a case object via

$result = civicrm_api3('case', 'create', $params);

This function on debugging api.php file is returning the case id but in my module it is returning the null value

I want it to return the case id. How would i do so? Here code Snippet

function form_test_form_submit($form, &$form_state)
$params = array( 
    'subject' => 'Test case',
    'contact_id' => 64771, 
    'case_type' => 'test', 

$case = testcase_create($params);

function testcase_create($params){
    require_once 'api/api.php';

        $result = civicrm_api3('case', 'create', $params); 
    catch (CiviCRM_API3_Exception $e) { 
        $errorMessage = $e->getMessage();
        $errorCode = $e->getErrorCode();
        $errorData = $e->getExtraParams();
        return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
    return $result; // the value of $result is NULL, where as in api.php it was not NULL as seen in debugging
  • I can able to create case in drupal custom module in earlier civicrm was upgraded that is xml problem.
    – M Sivani
    May 27 '15 at 7:56

This may be a permissions issue, depending on who is the logged-in user when your code runs and whether they have permission to create cases. If you want your code to run anyway regardless of who is logged-in, you could add 'check_permissions' => FALSE to your api $params.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.