Answers.Body: <p>I'd start with a case relationships view.</p>
  <p>Filter by relationship type, and case type.</p>
  <p>Bring in the case details via a views relationship
  And bring in the two contacts (A and B, from the relationship) again from views relationships</p>
  <p><a href="https://i.sstatic.net/cbDjI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cbDjI.png" alt="enter image description here" /></a></p>
  <p>And then apply the contextual/ drupal id filter to the B contact of the relationship</p>
  <p>Then you get Case Details and Contact A (client) Details for any case the logged in user has the specific role in.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-29T11:16:57.070Z
Answers.Text: This worked, thanks a lot.
Answers.UserDisplayName: emma
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-15T18:13:59.200Z
Answers.LastActivityDate: 2022-03-15T18:13:59.200Z
Answers.UserDisplayName: Craig Almond
Body: <p>I want to create a custom Dashboard with Drupal Views to substitute the built-in CiviCRM dashboard (because <a href="https://civicrm.stackexchange.com/questions/35848/civicase-dashboard-shows-cases-for-invisible-contacts">CiviCase dashboard shows cases for invisible contacts</a> ).</p>
  <p>I want to set a contextual filter on this logged in user's ID (<code>CiviCRM Drupal match table: Drupal User ID</code>).
  Then, I want to create several Relationships to access all the Case IDs of the cases this user coordinates: The currently logged in user is the &quot;Case Coordinator&quot;. In the &quot;Relationships&quot; section of Drupal Views, I include all of their Clients. Then I include all Case IDs on this Client.</p>
  <p>The problem is: This includes <strong>all</strong> Cases on a Client, no matter if the Case Coordinator of that case is the logged in user, or not. In other words: A Case Coordinator can see all the cases of one client in my custom dashboard, as soon as he coordinates one case on that client. This is undesired behavior. Every case coordinator should only see the cases he actually manages. This also distorts the numbers.</p>
  <p>Afaik, this behavior appears because the specific connection between Case Coordinator and Case ID is a <strong>CiviCRM Role</strong> instead of a <strong>relationship</strong> between entities. Only relationships can be included in a Drupal View. I can access the CiviCRM role as an array per API Call (<code>get Case</code>) though:</p>
  <pre><code>&quot;contacts&quot;: [
                  {
                      &quot;contact_id&quot;: &quot;76&quot;,
                      &quot;sort_name&quot;: &quot;client name&quot;,
                      &quot;display_name&quot;: &quot;client name&quot;,
                      &quot;email&quot;: &quot;client@email.org&quot;,
                      &quot;phone&quot;: &quot;0000&quot;,
                      &quot;birth_date&quot;: &quot;&quot;,
                      &quot;role&quot;: &quot;Client&quot;
                  },
                  {
                      &quot;contact_id&quot;: &quot;49&quot;,
                      &quot;display_name&quot;: &quot;coordinator name&quot;,
                      &quot;sort_name&quot;: &quot;coordinator name&quot;,
                      &quot;relationship_type_id&quot;: &quot;9&quot;,
                      &quot;role&quot;: &quot;Case Coordinator is&quot;,
                      &quot;email&quot;: &quot;coordinator@email.org&quot;,
                      &quot;phone&quot;: &quot;&quot;,
                      &quot;creator&quot;: &quot;1&quot;,
                      &quot;manager&quot;: &quot;1&quot;
                  }
              ],
  </code></pre>
  <p>Does anybody know how I can access this CiviCRM Role in Drupal Views? Can I &quot;convert&quot; it into a relationship? Or can I code a custom relationship that contains an API Call to that CiviCRM Role (where I am able to access the fields included by Relationships in my code, at least the Case ID)?</p>
  <p>I thought that maybe <a href="https://civicrm.stackexchange.com/questions/6782/adding-case-role-to-civicrm-cases-views">this</a> could be a solution, but it turns out the accepted answer only does the same solution that I tried above, except that it starts from the other end of the relationship chain (Case ID -&gt; Client -&gt; Case Coordinator). The problem that this returns too many entries remains (here: returns <strong>all</strong> Case Coordinators of that Client for each Case ID, not only Case Coordinator of this specific Case ID).</p>
  <p>I think it is an essential function that Case Coordinators can only view their &quot;own&quot; cases in a dashboard. That's why I wouldn't like to make any compromise here, if possible.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-15T19:50:12.243Z
Comments.Text: have you checked out Compucorps CiviCase extension. I am not recommending it (nor dishing it), just flagging that it offers a bunch of different displays etc https://github.com/compucorp/uk.co.compucorp.civicase and https://civicrm.stackexchange.com/questions/40127/which-civicase-compucore-or-v5
Comments.UserDisplayName: petednz - fuzion
Tags: <drupal-views><relationships><civicrm-entity><roles>
Title: Include a CiviCRM role into Drupal View (custom dashboard)
ThreadText: # Include a CiviCRM role into Drupal View (custom dashboard)
  
  (Asked by: username_0 on 2022-03-15)
  
  I want to create a custom Dashboard with Drupal Views to substitute the built-in CiviCRM dashboard (because CiviCase dashboard shows cases for invisible contacts ).
  I want to set a contextual filter on this logged in user's ID (CiviCRM Drupal match table: Drupal User ID).
  Then, I want to create several Relationships to access all the Case IDs of the cases this user coordinates: The currently logged in user is the "Case Coordinator". In the "Relationships" section of Drupal Views, I include all of their Clients. Then I include all Case IDs on this Client.
  The problem is: This includes all Cases on a Client, no matter if the Case Coordinator of that case is the logged in user, or not. In other words: A Case Coordinator can see all the cases of one client in my custom dashboard, as soon as he coordinates one case on that client. This is undesired behavior. Every case coordinator should only see the cases he actually manages. This also distorts the numbers.
  Afaik, this behavior appears because the specific connection between Case Coordinator and Case ID is a CiviCRM Role instead of a relationship between entities. Only relationships can be included in a Drupal View. I can access the CiviCRM role as an array per API Call (get Case) though:
  "contacts": [
                  {
                      "contact_id": "76",
                      "sort_name": "client name",
                      "display_name": "client name",
                      "email": "client@email.org",
                      "phone": "0000",
                      "birth_date": "",
                      "role": "Client"
                  },
                  {
                      "contact_id": "49",
                      "display_name": "coordinator name",
                      "sort_name": "coordinator name",
                      "relationship_type_id": "9",
                      "role": "Case Coordinator is",
                      "email": "coordinator@email.org",
                      "phone": "",
                      "creator": "1",
                      "manager": "1"
                  }
              ],
  
  Does anybody know how I can access this CiviCRM Role in Drupal Views? Can I "convert" it into a relationship? Or can I code a custom relationship that contains an API Call to that CiviCRM Role (where I am able to access the fields included by Relationships in my code, at least the Case ID)?
  I thought that maybe this could be a solution, but it turns out the accepted answer only does the same solution that I tried above, except that it starts from the other end of the relationship chain (Case ID -> Client -> Case Coordinator). The problem that this returns too many entries remains (here: returns all Case Coordinators of that Client for each Case ID, not only Case Coordinator of this specific Case ID).
  I think it is an essential function that Case Coordinators can only view their "own" cases in a dashboard. That's why I wouldn't like to make any compromise here, if possible.
  
  **Tags:** drupal-views, relationships, civicrm-entity, roles
  
  > **Comments:**
  > **username_1**: have you checked out Compucorps CiviCase extension. I am not recommending it (nor dishing it), just flagging that it offers a bunch of different displays etc https://github.com/compucorp/uk.co.compucorp.civicase and https://civicrm.stackexchange.com/questions/40127/which-civicase-compucore-or-v5  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-03-15. Score: 4 | Accepted answer
  
  I'd start with a case relationships view.
  
  Filter by relationship type, and case type.
  
  Bring in the case details via a views relationship
  And bring in the two contacts (A and B, from the relationship) again from views relationships
  
  [![enter image description here](https://i.sstatic.net/cbDjI.png)](https://i.sstatic.net/cbDjI.png)
  
  And then apply the contextual/ drupal id filter to the B contact of the relationship
  
  Then you get Case Details and Contact A (client) Details for any case the logged in user has the specific role in.
  
  > **Comments:**
  > **username_0**: This worked, thanks a lot.  
  
  ---
  
  