Answers.Body: <p>I would hook on <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/</a> to find cases being closed then do the work from there. I would follow the civicrm_option_value grouping field to determine if a status represents closed. </p>
  
  <p>This seems like an opportunity for a nice small single purpose extension. Maybe 3-4h to develop and publish.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T18:30:38.197Z
Answers.Text: That would only catch cases closed via UI, so it might need a little more, like hookPost.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T21:49:13.940Z
Answers.Text: Another note: I don't know how many people are using this feature but you can have more than one case status that represents closed. It's not the "resolved/closed" case status itself that determines closed it's the `grouping` field in civicrm_option_value that is actually used to determine which case statuses represent closed. A use-case would be something like if you wanted to capture closure reasons, e.g. "Closed-claim approved" vs "Closed-claim denied".
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T22:28:19.700Z
Answers.Text: He Demerit - yep we are aware of the setting that specifies if a Status means closed/resolved, though seems that is purely in the code eg for Searches and not in the db as a value
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T23:13:34.637Z
Answers.Text: I mean if you look in CRM/Case/Form/Activity/ChangeCaseStatus.php in endPostProcess(), the check for closed vs. open is against the `grouping` field in civicrm_option_value for the case status that was selected on the form, not against the status value itself, e.g. if you select Urgent, it checks to see what the grouping field for Urgent has in civicrm_option_value.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T23:15:59.750Z
Answers.Text: `$groupingValues = CRM_Core_OptionGroup::values('case_status', FALSE, TRUE, FALSE, NULL, 'value');`
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-17T16:34:22.760Z
Answers.Text: I tested CiviCase, but didn't adopt it precisely because of the issue @petednz identifies. My cases often closed early, which resulted in a mess of scheduled activities that needed to be closed or cleaned up manually.  If anyone wants to open a Make it Happen campaign count me as a contributor.
Answers.UserDisplayName: Elijah van der Giessen
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-17T19:53:11.797Z
Answers.Text: elijah can you PM me via Chat? or fuzion.co.nz
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T18:11:58.737Z
Answers.LastActivityDate: 2019-04-17T20:36:14.723Z
Answers.LastEditDate: 2019-04-17T20:36:14.723Z
Answers.UserDisplayName: Joe Murray
Body: <p>anyone have a working model of this. we thought about drupal/civi rules but may just add in an extension. </p>
  
  <p>seems to us that it could be quite a generic solution, after all, when a Case is Closed you don't want to keep finding Activities that may be eg Scheduled</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-30T10:40:41.567Z
Comments.Text: Similarly for inactive cases. At present, scheduled reminders are still send out, even if a case has been marked as inactive. Not sure how to handle this. It would be possible to change the status of all the uncompleted case activities, but then again I can imaging needing to reactivate a case with all the activity status information unaltered.
Comments.UserDisplayName: Jern
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-10T04:44:29.557Z
Comments.Text: If you mean the autopopulated ones from the timeline when the activities first get added (database field is_auto=1), that sounds familiar but I think it was decided not to. In any case (pun) it seems like a useful thing. Only thing I can think is that if you're auditing cases for "completion percentage" or something like that and want to be able to tell them apart from actual cancelled, then might want to use a configurable custom status.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-11T07:01:56.073Z
Comments.Text: our plan would be to set them to a Status that is different than Completed, eg Cancelled or something that would help differentiate. and no we aren't using a timeline.
Comments.UserDisplayName: petednz - fuzion
Tags: <civicase><activities>
Title: When a Case is set to Closed we would like all un-Completed Activities on the Case to have their Status changed (eg to Cancelled
ThreadText: # When a Case is set to Closed we would like all un-Completed Activities on the Case to have their Status changed (eg to Cancelled
  
  (Asked by: username_0 on 2019-04-10)
  
  anyone have a working model of this. we thought about drupal/civi rules but may just add in an extension.
  
  seems to us that it could be quite a generic solution, after all, when a Case is Closed you don't want to keep finding Activities that may be eg Scheduled
  
  **Tags:** civicase, activities
  
  > **Comments:**
  > **username_2**: If you mean the autopopulated ones from the timeline when the activities first get added (database field is_auto=1), that sounds familiar but I think it was decided not to. In any case (pun) it seems like a useful thing. Only thing I can think is that if you're auditing cases for "completion percentage" or something like that and want to be able to tell them apart from actual cancelled, then might want to use a configurable custom status.  
  > **username_0**: our plan would be to set them to a Status that is different than Completed, eg Cancelled or something that would help differentiate. and no we aren't using a timeline.  
  > **username_1**: Similarly for inactive cases. At present, scheduled reminders are still send out, even if a case has been marked as inactive. Not sure how to handle this. It would be possible to change the status of all the uncompleted case activities, but then again I can imaging needing to reactivate a case with all the activity status information unaltered.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2019-04-16. Score: 1
  
  I would hook on <https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/> to find cases being closed then do the work from there. I would follow the civicrm\_option\_value grouping field to determine if a status represents closed.
  
  This seems like an opportunity for a nice small single purpose extension. Maybe 3-4h to develop and publish.
  
  > **Comments:**
  > **username_2**: That would only catch cases closed via UI, so it might need a little more, like hookPost.  
  > **username_2**: Another note: I don't know how many people are using this feature but you can have more than one case status that represents closed. It's not the "resolved/closed" case status itself that determines closed it's the `grouping` field in civicrm_option_value that is actually used to determine which case statuses represent closed. A use-case would be something like if you wanted to capture closure reasons, e.g. "Closed-claim approved" vs "Closed-claim denied".  
  > **username_0**: He username_2 - yep we are aware of the setting that specifies if a Status means closed/resolved, though seems that is purely in the code eg for Searches and not in the db as a value  
  > **username_2**: I mean if you look in CRM/Case/Form/Activity/ChangeCaseStatus.php in endPostProcess(), the check for closed vs. open is against the `grouping` field in civicrm_option_value for the case status that was selected on the form, not against the status value itself, e.g. if you select Urgent, it checks to see what the grouping field for Urgent has in civicrm_option_value.  
  > **username_2**: `$groupingValues = CRM_Core_OptionGroup::values('case_status', FALSE, TRUE, FALSE, NULL, 'value');`  
  > **username_4**: I tested CiviCase, but didn't adopt it precisely because of the issue @username_0 identifies. My cases often closed early, which resulted in a mess of scheduled activities that needed to be closed or cleaned up manually.  If anyone wants to open a Make it Happen campaign count me as a contributor.  
  > **username_0**: username_4 can you PM me via Chat? or username_0.co.nz  
  
  ---
  
  