Answers.Body: <p>Smartgroup criteria are stored using the SavedSearch api.  Use the API explorer (<code>/civicrm/api#explorer</code>) and select entity: <code>SavedSearch</code> action: <code>get</code></p>
  
  <p>In each of the <code>values</code> returned, there is a <code>form_values</code> key with a  list of components that define the search. The list varies depending on how the search was created.</p>
  
  <p>If you look at one created from an include/exclude search, then it contains components like: </p>
  
  <pre><code>        [
              "excludeGroups",
              "IN",
              [
                  "4"
              ],
              "0",
              "0"
          ],
  </code></pre>
  
  <p>Without checking the details of each of those parameters, it's very likely that group_id 4 is involved in this query.</p>
  
  <p>Likewise for an example created from Advanced Search:</p>
  
  <pre><code>           [
              "group",
              "=",
              {
                  "IN": [
                      "5"
                  ]
              },
              "0",
              "0"
          ],
  </code></pre>
  
  <p>So group_id 5 is involved in this.</p>
  
  <p>A smart group is linked to a SavedSearch by the <code>saved_search_id</code> attribute - in API Explorer, set entity to <code>Group</code>, action to <code>get</code> and look for <code>saved_search_id</code></p>
  
  <p>If you just want to understand which groups depend on others, then visual inspection of the <code>SavedSearch.get</code> output might be enough.</p>
  
  <p>Expanding this into an extension to show those dependencies would be nice, but tricky since the components of the <code>form_values</code> list depends on how the search was created.  You would need to experiment with the various ways of creating smart groups to identify all the syntaxes that relate to groups but even then, custom searches define their own definitions (as include/exclude does), so it would be easy to miss some giving incomplete results.  In other words, it would be easier to say "This group does depend on this other group" rather then "This group does not depend on this other group".</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-20T09:02:47.543Z
Answers.LastActivityDate: 2017-06-20T09:02:47.543Z
Answers.UserDisplayName: Aidan
Body: <p>Is there a way in which I can easily see how the smart groups are related (as in <strong>include / exclude</strong> search)?</p>
  
  <p>When I try to build a group which selects the contacts I need, I often combine multiple smart groups to arrive to necessary results. It would be very convenient to see how they are related. Is there an easy way to tell, if a particular group is used in some other group (so that it could be modified or deleted without worry)? Or should I check all other groups to make sure that none of them actually uses the group I am about to delete/modify?</p>
  
Tags: <groups><smartgroups>
Title: Can I see (smart) group relations?
ThreadText: # Can I see (smart) group relations?
  
  (Asked by: username_0 on 2017-06-19)
  
  Is there a way in which I can easily see how the smart groups are related (as in **include / exclude** search)?
  
  When I try to build a group which selects the contacts I need, I often combine multiple smart groups to arrive to necessary results. It would be very convenient to see how they are related. Is there an easy way to tell, if a particular group is used in some other group (so that it could be modified or deleted without worry)? Or should I check all other groups to make sure that none of them actually uses the group I am about to delete/modify?
  
  **Tags:** groups, smartgroups
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-06-20. Score: 1
  
  Smartgroup criteria are stored using the SavedSearch api.  Use the API explorer (/civicrm/api#explorer) and select entity: SavedSearch action: get
  In each of the values returned, there is a form_values key with a  list of components that define the search. The list varies depending on how the search was created.
  If you look at one created from an include/exclude search, then it contains components like: 
          [
              "excludeGroups",
              "IN",
              [
                  "4"
              ],
              "0",
              "0"
          ],
  
  Without checking the details of each of those parameters, it's very likely that group_id 4 is involved in this query.
  Likewise for an example created from Advanced Search:
             [
              "group",
              "=",
              {
                  "IN": [
                      "5"
                  ]
              },
              "0",
              "0"
          ],
  
  So group_id 5 is involved in this.
  A smart group is linked to a SavedSearch by the saved_search_id attribute - in API Explorer, set entity to Group, action to get and look for saved_search_id
  If you just want to understand which groups depend on others, then visual inspection of the SavedSearch.get output might be enough.
  Expanding this into an extension to show those dependencies would be nice, but tricky since the components of the form_values list depends on how the search was created.  You would need to experiment with the various ways of creating smart groups to identify all the syntaxes that relate to groups but even then, custom searches define their own definitions (as include/exclude does), so it would be easy to miss some giving incomplete results.  In other words, it would be easier to say "This group does depend on this other group" rather then "This group does not depend on this other group".
  
  
  ---
  
  