0

I am trying to create a custom group and custom field using extension.
I created seperate funtion

function custom_group_create_example() {
$params = array(
    'title' => 'Test_Group_1',
    'name' => 'test_group_1',
    'extends' => array(
        '0' => 'Individual',
    ),
    'weight' => 4,
    'collapse_display' => 1,
    'style' => 'Inline',
    'help_pre' => 'This is Pre Help For Test Group 1',
    'help_post' => 'This is Post Help For Test Group 1',
    'is_active' => 1,
);

try{
    $result = civicrm_api3('CustomGroup', 'create', $params);
}
catch (CiviCRM_API3_Exception $e) {
    // Handle error here.
    $errorMessage = $e->getMessage();
    $errorCode = $e->getErrorCode();
    $errorData = $e->getExtraParams();
    return array(
        'is_error' => 1,
        'error_message' => $errorMessage,
        'error_code' => $errorCode,
        'error_data' => $errorData,
    );
}

return $result;

}

I call this funtion into

function contact_civicrm_install()

this funtion(hook).
But problem is that it is not creating any custom group.
How to resolve this problem.

2
  • What do you mean by: "I call this funtion into function contact_civicrm_install() this funtion(hook). "? I am unclear what you are doing here, and contact is probably not a very smart name for an extension and invites clashes. Will add an example as answer. Dec 12, 2018 at 15:23
  • Finally, it's work properly.
    – Dipak Giri
    Dec 13, 2018 at 5:21

1 Answer 1

1

Here is how I add custom groups and fields:

  • as a first step, add an upgrader to your extension with civix generate:upgrader
  • then add the call to your creating function to the install function in the upgrader:
     public function install() {
        // install custom groups and fields
        CRM_Example_CustomData::createGroupsAndFields();

  • I also think your extends does not have to be an array? I use
'extends' => 'Individual',

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.