Answers.Body: <p>Here is how I add custom groups and fields:</p>
  
  <ul>
  <li>as a first step, add an upgrader to your extension with civix generate:upgrader</li>
  <li>then add the call to your creating function to the install function in the upgrader:</li>
  </ul>
  
  <pre>
       public function install() {
          // install custom groups and fields
          CRM_Example_CustomData::createGroupsAndFields();
  
  </pre>
  
  <ul>
  <li>I also think your extends does not have to be an array? I use </li>
  </ul>
  
  <pre>
  'extends' => 'Individual',
  </pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-12T15:44:07.507Z
Answers.LastActivityDate: 2018-12-12T15:44:07.507Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>I am trying to create a custom group and custom field using extension.<br>
  I created seperate funtion <br></p>
  
  <pre><code>function custom_group_create_example() {
  $params = array(
      'title' =&gt; 'Test_Group_1',
      'name' =&gt; 'test_group_1',
      'extends' =&gt; array(
          '0' =&gt; 'Individual',
      ),
      'weight' =&gt; 4,
      'collapse_display' =&gt; 1,
      'style' =&gt; 'Inline',
      'help_pre' =&gt; 'This is Pre Help For Test Group 1',
      'help_post' =&gt; 'This is Post Help For Test Group 1',
      'is_active' =&gt; 1,
  );
  
  try{
      $result = civicrm_api3('CustomGroup', 'create', $params);
  }
  catch (CiviCRM_API3_Exception $e) {
      // Handle error here.
      $errorMessage = $e-&gt;getMessage();
      $errorCode = $e-&gt;getErrorCode();
      $errorData = $e-&gt;getExtraParams();
      return array(
          'is_error' =&gt; 1,
          'error_message' =&gt; $errorMessage,
          'error_code' =&gt; $errorCode,
          'error_data' =&gt; $errorData,
      );
  }
  
  return $result;
  </code></pre>
  
  <p>}</p>
  
  <p>I call this funtion into </p>
  
  <blockquote>
    <p>function contact_civicrm_install()</p>
  </blockquote>
  
  <p>this funtion(hook).<br>
  But problem is that it is not creating any custom group.<br>
  How to resolve this problem.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-12T15:23:39.583Z
Comments.Text: 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.
Comments.UserDisplayName: ErikH - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-13T05:21:21.947Z
Comments.Text: Finally, it's work properly.
Comments.UserDisplayName: Dipak Giri
Tags: <extension>
Title: creating a custom group and and field using extension
ThreadText: # creating a custom group and and field using extension
  
  (Asked by: username_0 on 2018-12-12)
  
  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.
  
  **Tags:** extension
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: Finally, it's work properly.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-12-12. Score: 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',
  
  
  ---
  
  