Answers.Body: <p>Not an answer but rather a kind of half temporary workaround, posting in case someone finds it useful, and beacuse you metioned you are familiar with creating an extension/module.</p>
  <p>You can use <a href="https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm" rel="nofollow noreferrer">hook_civicrm_buildForm</a> to alter the form status id based on activity type_id/name, this soultion is <strong>not user friendly</strong> and it <strong>won't work from <code>standalone</code> context</strong>, ie when using <strong>Contacts -&gt; New Activity</strong>, but it can do the trick if you can live with that and don't have a ton of Activities Types.</p>
  <p>Hope it helps, and let me know if there's anything unclear.</p>
  <pre><code>// Implement myextension_civicrm_buildForm 
  function myextension_civicrm_buildForm( $formName, &amp;$form ){
      if ( $formName == 'CRM_Activity_Form_Activity' ) {
          // Hook only when adding an Activity and the context is not standalone
          if ( $form-&gt;getAction() == CRM_Core_Action::ADD &amp;&amp; $form-&gt;_context != 'standalone' ) {
          
              // The array that holds the Status and Activities that should have that status by default
              // and the only bit that you'll have to change/upadte when you add more activities and statuses
              $activities = array( 
                  'Completed' =&gt; array( 'Meeting', 'Phone Call' ),
                  'No-Show' =&gt; array( 'Custom Activity' ),
                  'My Custom Status' =&gt; ( 'Another Custom Activity', 'Yet Another Custom Activity' )
              );
  
              foreach ($activities as $status =&gt; $activity_types) {
                  if ( in_array( $form-&gt;_activityTypeName, $activity_types ) ) {
                      // Get status_id by Label
                      $result = civicrm_api3('OptionValue', 'getsingle', array(
                          'sequential' =&gt; 1,
                          'option_group_id' =&gt; 'activity_status',
                          'label' =&gt; $status,
                      ));
                      // Set the default value in the form
                      $defaults['status_id'] = $result['value'];
                      $form-&gt;setDefaults($defaults);
                  }
              }
          }
      } 
  }
  </code></pre>
  <p><strong>EDIT</strong>
  If you want to do the same thing when in <code>standalone</code> context you could add some jQuery/JavaScript to the form, see below updated snippet and JS snippet.</p>
  <pre><code>// Implement myextension_civicrm_buildForm 
  function myextension_civicrm_buildForm( $formName, &amp;$form ){
      if ( $formName == 'CRM_Activity_Form_Activity' ) {
          // Hook only when adding an Activity and the context is not standalone
          if ( $form-&gt;getAction() == CRM_Core_Action::ADD ) {
          
              // The array that holds the Status and Activities that should have that status by default
              // and the only bit that you'll have to change/upadte when you add more activities and statuses
              $activities = array( 
                  'Completed' =&gt; array( 'Meeting', 'Phone Call' ),
                  'No-Show' =&gt; array( 'Custom Activity' ),
                  'My Custom Status' =&gt; ( 'Another Custom Activity', 'Yet Another Custom Activity' )
              );
              
              if( $form-&gt;_context != 'standalone' ){
                  foreach ($activities as $status =&gt; $activity_types) {
                      if ( in_array( $form-&gt;_activityTypeName, $activity_types ) ) {
                          // Get status_id by Label
                          $result = civicrm_api3('OptionValue', 'getsingle', array(
                              'sequential' =&gt; 1,
                              'option_group_id' =&gt; 'activity_status',
                              'label' =&gt; $status,
                          ));
                          // Set the default value in the form
                          $defaults['status_id'] = $result['value'];
                          $form-&gt;setDefaults($defaults);
                      }
                  }
              } else {
                  // Make $activites available in JS
                  CRM_Core_Resources::singleton()-&gt;addVars( 'myextension', array( 'defaultedActivites' =&gt; $activities ) );
                  // Add JS script
                  CRM_Core_Resources::singleton()-&gt;addScriptFile( 'myextension', 'defaultedActivites.js' );
              }
          }
      } 
  }
  
  // in your JS script =&gt; defaultedActivites.js
  // Same principle as above, there might a better way to do this JS-wise but that should do it
  CRM.$(function($) {
      $( '#activity_type_id' ).change( function(){
          var defaultedActivites = CRM.vars.myextension.defaultedActivites; // Store defaultedActivites
          var activity = $( this ).select2( 'data' ); // Get the select2 Activity object, ie Activty type
          $.each( defaultedActivites, function( status, activityTypes ){
              activityTypes.map( function( currentActivity ){
                  if( currentActivity == activity.text ){
                      // Get status_id by label
                      CRM.api3( 'OptionValue', 'getsingle', {
                          'sequential': 1,
                          'option_group_id': 'activity_status',
                          'label': status
                      }).done( function( statusId ) {
                          // Set default value
                          $(&quot;#status_id&quot;).val( statusId.value ).trigger(&quot;change&quot;);
                      });
                  }
              })
          })
      });
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-04T09:05:44.943Z
Answers.Text: Thanks, I will probably use this. Just had a play with standalone context and custom fields, and when you pick the activity type the custom fields appear so there is some process going on there that could be hijacked - if standalone context is important. I think in our workflow it's not
Answers.UserDisplayName: naomi
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-04T15:23:03.457Z
Answers.Text: @naomi I've updated the answer to cover also the `standalone` context using a bit of javascript
Answers.UserDisplayName: Andrei
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2016-11-04T00:58:51.643Z
Answers.LastActivityDate: 2023-03-20T03:05:19.270Z
Answers.LastEditDate: 2023-03-20T03:05:19.270Z
Answers.UserDisplayName: Andrei
Body: <p>Wondering how to do this, it clearly would need an extension (or, as I have done for other things, a Drupal module) but just looking for any tips really.</p>
  
  <p>I would like to be able to specify a default status when defining an activity type. When case workers are with a client they take the opportunity to do whatever they can at the time, whatever presents itself, e.g. refer the client to another organisation, or make copies of documents they brought in. These activities are normally logged at the same time that they are completed. It is annoying for the worker to have to manually set the activity to completed when they log it, they often don't, which results in "scheduled" activities lying around that are actually completed. But other types of activities are genuinely scheduled for the future, e.g. "review" meetings that are automatically generated for certain lengths of time in the future when a client is taken on. </p>
  
  <p>So it would be good if, when defining an activity type, we could state whether it is default completed or default scheduled.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-03T19:14:46.617Z
Comments.Text: Naomi, i concur. reminds me it would also be nice if one could offer different Status for different Activity Types sinc sometimes one wants a specific Status that is only applicable to a particular Activity Type. just wishing out loud but i guess it relates in the sense of having some configurability on a per Activity Type basis.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-03T21:34:51.760Z
Comments.Text: See http://civicrm.stackexchange.com/questions/15074/how-to-make-status-always-completed-for-activities-added-to-a-case which is a way to do what you want by directly updating the database.  Your use case is exactly the same as mine for 2 clients.  So would be good to have this available in the UI
Comments.UserDisplayName: Andy Clark
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-04T08:54:58.950Z
Comments.Text: Thanks Andy, interesting stuff following those links. I will probably go with the buildForm method. It would be nice to add something to the form when creating a new activity type, too, in order to pick which default status it should have. Which I guess is what you want too. If I have time I'll do it and let you know! Big if!
Comments.UserDisplayName: naomi
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-04T08:59:43.020Z
Comments.Text: Actually, updating the database directly looks a lot easier...
Comments.UserDisplayName: naomi
Tags: <drupal><extension><civicase><activities>
Title: Different default status for different activity types?
ThreadText: # Different default status for different activity types?
  
  (Asked by: username_0 on 2016-11-03)
  
  Wondering how to do this, it clearly would need an extension (or, as I have done for other things, a Drupal module) but just looking for any tips really.
  
  I would like to be able to specify a default status when defining an activity type. When case workers are with a client they take the opportunity to do whatever they can at the time, whatever presents itself, e.g. refer the client to another organisation, or make copies of documents they brought in. These activities are normally logged at the same time that they are completed. It is annoying for the worker to have to manually set the activity to completed when they log it, they often don't, which results in "scheduled" activities lying around that are actually completed. But other types of activities are genuinely scheduled for the future, e.g. "review" meetings that are automatically generated for certain lengths of time in the future when a client is taken on.
  
  So it would be good if, when defining an activity type, we could state whether it is default completed or default scheduled.
  
  **Tags:** drupal, extension, civicase, activities
  
  > **Comments:**
  > **username_1**: Naomi, i concur. reminds me it would also be nice if one could offer different Status for different Activity Types sinc sometimes one wants a specific Status that is only applicable to a particular Activity Type. just wishing out loud but i guess it relates in the sense of having some configurability on a per Activity Type basis.  
  > **username_2**: See http://civicrm.stackexchange.com/questions/15074/how-to-make-status-always-completed-for-activities-added-to-a-case which is a way to do what you want by directly updating the database.  Your use case is exactly the same as mine for 2 clients.  So would be good to have this available in the UI  
  > **username_0**: Thanks Andy, interesting stuff following those links. I will probably go with the buildForm method. It would be nice to add something to the form when creating a new activity type, too, in order to pick which default status it should have. Which I guess is what you want too. If I have time I'll do it and let you know! Big if!  
  > **username_0**: Actually, updating the database directly looks a lot easier...  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2016-11-04. Score: 3 | Accepted answer
  
  Not an answer but rather a kind of half temporary workaround, posting in case someone finds it useful, and beacuse you metioned you are familiar with creating an extension/module.
  You can use hook_civicrm_buildForm to alter the form status id based on activity type_id/name, this soultion is not user friendly and it won't work from standalone context, ie when using Contacts -> New Activity, but it can do the trick if you can live with that and don't have a ton of Activities Types.
  Hope it helps, and let me know if there's anything unclear.
  // Implement myextension_civicrm_buildForm 
  function myextension_civicrm_buildForm( $formName, &$form ){
      if ( $formName == 'CRM_Activity_Form_Activity' ) {
          // Hook only when adding an Activity and the context is not standalone
          if ( $form->getAction() == CRM_Core_Action::ADD && $form->_context != 'standalone' ) {
          
              // The array that holds the Status and Activities that should have that status by default
              // and the only bit that you'll have to change/upadte when you add more activities and statuses
              $activities = array( 
                  'Completed' => array( 'Meeting', 'Phone Call' ),
                  'No-Show' => array( 'Custom Activity' ),
                  'My Custom Status' => ( 'Another Custom Activity', 'Yet Another Custom Activity' )
              );
  
              foreach ($activities as $status => $activity_types) {
                  if ( in_array( $form->_activityTypeName, $activity_types ) ) {
                      // Get status_id by Label
                      $result = civicrm_api3('OptionValue', 'getsingle', array(
                          'sequential' => 1,
                          'option_group_id' => 'activity_status',
                          'label' => $status,
                      ));
                      // Set the default value in the form
                      $defaults['status_id'] = $result['value'];
                      $form->setDefaults($defaults);
                  }
              }
          }
      } 
  }
  
  EDIT
  If you want to do the same thing when in standalone context you could add some jQuery/JavaScript to the form, see below updated snippet and JS snippet.
  // Implement myextension_civicrm_buildForm 
  function myextension_civicrm_buildForm( $formName, &$form ){
      if ( $formName == 'CRM_Activity_Form_Activity' ) {
          // Hook only when adding an Activity and the context is not standalone
          if ( $form->getAction() == CRM_Core_Action::ADD ) {
          
              // The array that holds the Status and Activities that should have that status by default
              // and the only bit that you'll have to change/upadte when you add more activities and statuses
              $activities = array( 
                  'Completed' => array( 'Meeting', 'Phone Call' ),
                  'No-Show' => array( 'Custom Activity' ),
                  'My Custom Status' => ( 'Another Custom Activity', 'Yet Another Custom Activity' )
              );
              
              if( $form->_context != 'standalone' ){
                  foreach ($activities as $status => $activity_types) {
                      if ( in_array( $form->_activityTypeName, $activity_types ) ) {
                          // Get status_id by Label
                          $result = civicrm_api3('OptionValue', 'getsingle', array(
                              'sequential' => 1,
                              'option_group_id' => 'activity_status',
                              'label' => $status,
                          ));
                          // Set the default value in the form
                          $defaults['status_id'] = $result['value'];
                          $form->setDefaults($defaults);
                      }
                  }
              } else {
                  // Make $activites available in JS
                  CRM_Core_Resources::singleton()->addVars( 'myextension', array( 'defaultedActivites' => $activities ) );
                  // Add JS script
                  CRM_Core_Resources::singleton()->addScriptFile( 'myextension', 'defaultedActivites.js' );
              }
          }
      } 
  }
  
  // in your JS script => defaultedActivites.js
  // Same principle as above, there might a better way to do this JS-wise but that should do it
  CRM.$(function($) {
      $( '#activity_type_id' ).change( function(){
          var defaultedActivites = CRM.vars.myextension.defaultedActivites; // Store defaultedActivites
          var activity = $( this ).select2( 'data' ); // Get the select2 Activity object, ie Activty type
          $.each( defaultedActivites, function( status, activityTypes ){
              activityTypes.map( function( currentActivity ){
                  if( currentActivity == activity.text ){
                      // Get status_id by label
                      CRM.api3( 'OptionValue', 'getsingle', {
                          'sequential': 1,
                          'option_group_id': 'activity_status',
                          'label': status
                      }).done( function( statusId ) {
                          // Set default value
                          $("#status_id").val( statusId.value ).trigger("change");
                      });
                  }
              })
          })
      });
  });
  
  > **Comments:**
  > **username_0**: Thanks, I will probably use this. Just had a play with standalone context and custom fields, and when you pick the activity type the custom fields appear so there is some process going on there that could be hijacked - if standalone context is important. I think in our workflow it's not  
  > **username_3**: @username_0 I've updated the answer to cover also the `standalone` context using a bit of javascript  
  
  ---
  
  