Answers.Body: <p>I have an example of how I deal with creating custom groups and fields in an extension here: <a href="https://lab.civicrm.org/partners/civicoop/dmgeneriek/tree/master/CRM/Dmgeneriek/ConfigItems" rel="nofollow noreferrer">https://lab.civicrm.org/partners/civicoop/dmgeneriek/tree/master/CRM/Dmgeneriek/ConfigItems</a></p>
  
  <ul>
  <li>The definition of the custom groups and fields are in the resources folder in json files</li>
  <li>The ConfigItems class is initiated in the Upgrader (see <a href="https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-upgrader" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-upgrader</a>)</li>
  </ul>
  
  <p>I recommend avoiding using hard coded custom group id's in your code.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-06T09:01:50.467Z
Answers.LastActivityDate: 2018-11-06T09:01:50.467Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>I am creating new extension.<br>
  I am adding a new custom field into Activity tab but it's not working<br></p>
  
  <h2>//Creating a custom group for survey</h2>
  
  <pre><code>function custom_group_create_survey(){
  $survey_custom_group = array(
      "id" =&gt; "10",
      "name" =&gt; "API_survey",
      "title" =&gt; "API survey",
      "extends" =&gt; "Activity",
      "extends_entity_column_value" =&gt; [
          "1"
      ],
      "style" =&gt; "Inline",
      "collapse_display" =&gt; "1",
      "weight" =&gt; "   3",
      "is_active" =&gt; "1",
      "table_name" =&gt; "civicrm_value_API_sur__5",
      "is_multiple" =&gt; "0",
      "collapse_adv_display" =&gt; "0",
      "created_id" =&gt; "2",
      "created_date" =&gt; "",
      "is_reserved" =&gt; "0",
      "is_public" =&gt; "1"
  );
  
  try{
      $result = civicrm_api3('CustomGroup', 'create', $survey_custom_group);
  }
  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>
  
  <pre><code>function custom_field_create_survey() {
  $params = array(
      'custom_group_id' =&gt; 10,
      'name' =&gt; 'test_textfield2',
      'label' =&gt; 'Name1',
      'html_type' =&gt; 'Text',
      'data_type' =&gt; 'String',
      'default_value' =&gt; 'abc',
      'weight' =&gt; 4,
      'is_required' =&gt; 1,
      'is_searchable' =&gt; 0,
      'is_active' =&gt; 1,
  );
  
  try{
      $result = civicrm_api3('CustomField', '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 am calling these functions into following hook</p>
  
  <h2> </h2>
  
  <pre><code>function surveytab_civicrm_install() {
  custom_group_create_survey();
  custom_field_create_survey();
  </code></pre>
  
  <p>_surveytab_civix_civicrm_install();
  }
   ## </p>
  
  <p><a href="https://i.sstatic.net/9TbM6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9TbM6.png" alt="This is created by using custom field (administer)"></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-06T07:49:46.103Z
Comments.Text: Are you getting any error in your CiviCRM log or general error log?
Comments.UserDisplayName: ErikH - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-06T08:37:41.197Z
Comments.Text: No any error. I checked in API explorer.
Comments.UserDisplayName: Dipak Giri
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-06T08:53:09.870Z
Comments.Text: What is the message of the Exception? Or is there no exception?
Comments.UserDisplayName: ErikH - CiviCooP
Tags: <api><hooks><civix>
Title: I am trying to insert custom tab into Activity tab but it is not working
ThreadText: # I am trying to insert custom tab into Activity tab but it is not working
  
  (Asked by: username_0 on 2018-11-06)
  
  I am creating new extension.  
  I am adding a new custom field into Activity tab but it's not working
  
  ## //Creating a custom group for survey
  
  ```
  function custom_group_create_survey(){
  $survey_custom_group = array(
      "id" => "10",
      "name" => "API_survey",
      "title" => "API survey",
      "extends" => "Activity",
      "extends_entity_column_value" => [
          "1"
      ],
      "style" => "Inline",
      "collapse_display" => "1",
      "weight" => "   3",
      "is_active" => "1",
      "table_name" => "civicrm_value_API_sur__5",
      "is_multiple" => "0",
      "collapse_adv_display" => "0",
      "created_id" => "2",
      "created_date" => "",
      "is_reserved" => "0",
      "is_public" => "1"
  );
  
  try{
      $result = civicrm_api3('CustomGroup', 'create', $survey_custom_group);
  }
  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;
  
  ```
  
  }
  
  ```
  function custom_field_create_survey() {
  $params = array(
      'custom_group_id' => 10,
      'name' => 'test_textfield2',
      'label' => 'Name1',
      'html_type' => 'Text',
      'data_type' => 'String',
      'default_value' => 'abc',
      'weight' => 4,
      'is_required' => 1,
      'is_searchable' => 0,
      'is_active' => 1,
  );
  
  try{
      $result = civicrm_api3('CustomField', '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 am calling these functions into following hook
  
  ## 
  
  ```
  function surveytab_civicrm_install() {
  custom_group_create_survey();
  custom_field_create_survey();
  
  ```
  
  \_surveytab\_civix\_civicrm\_install();
  }
  ##
  
  [![This is created by using custom field (administer)](https://i.sstatic.net/9TbM6.png)](https://i.sstatic.net/9TbM6.png)
  
  **Tags:** api, hooks, civix
  
  > **Comments:**
  > **username_1**: Are you getting any error in your CiviCRM log or general error log?  
  > **username_0**: No any error. I checked in API explorer.  
  > **username_1**: What is the message of the Exception? Or is there no exception?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-11-06. Score: 1
  
  I have an example of how I deal with creating custom groups and fields in an extension here: <https://lab.civicrm.org/partners/username_1/dmgeneriek/tree/master/CRM/Dmgeneriek/ConfigItems>
  
  * The definition of the custom groups and fields are in the resources folder in json files
  * The ConfigItems class is initiated in the Upgrader (see <https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-upgrader>)
  
  I recommend avoiding using hard coded custom group id's in your code.
  
  
  ---
  
  