Answers.Body: <p>The contact selector is an <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/EntityRef+Fields" rel="nofollow">EntityRef field</a>. If you'd like to "enforce" a certain group or other filter on this field, you can do so with a small amount of custom code on your site.</p>
  
  <p>Modifying a form in CiviCRM depends on how the form is generated. Because this form is written in javascript, I recommend adding a custom js file to the CiviCase dashboard screen. It simply needs to add <a href="https://api.jquery.com/data/" rel="nofollow">data</a> to the two fields (<code>edit_role_contact_id</code> and <code>add_role_contact_id</code>) that specifies the group_id of your group.</p>
  
  <p>You can either use a custom module/plugin on your website or <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Create+a+Module+Extension" rel="nofollow">create an extension</a> to add your javascript file using <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Resource+Reference" rel="nofollow">CRM_Core_Resources</a> from <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Hook+Reference" rel="nofollow">a hook</a>. <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseSummary" rel="nofollow">hook_civicrm_caseSummary</a> might be a good one, you wouldn't be using it for exactly its intended purpose but it fires on the right screen.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-27T10:55:34.230Z
Answers.Text: Where do I read up on implementing such a custom addition? I am a seasoned programmer...
Answers.UserDisplayName: thoni56
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-27T14:12:40.403Z
Answers.Text: I had given some doc links already but just edited the post to add more. Happy coding :)
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-01T10:29:29.640Z
Answers.Text: Ok, partially there. What JS object should I add the data to? How do I find out?
Answers.UserDisplayName: thoni56
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-01T17:12:12.313Z
Answers.Text: Add it directly to the form elements in the dom. I gave you their names above.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T07:37:00.907Z
Answers.Text: thoni56, did you get this working?  If so, can you share what you did?  I want to do the same thing, and having an example would save me a lot of time.  Thanks!
Answers.UserDisplayName: Norris
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-15T14:14:27.743Z
Answers.Text: I can edit templates/CRM/Case/Form/CaseView.js to add "group, 58" to the params defining edit_role_contact_id, successfully filtering by the group, but putting my modified file into my template override directory doesn't change anything - should it?
  
  I can't for the life of me figure out how to access the add_role_contact_id field from a separate javascript file.  I can attach data of ("group", 58) to other elements on the page and use alert() to echo them back, but doing so with $('#editCaseRoleDialog') or $('[name=edit_role_contact_id]') results in "undefined".  So close - what am I missing?
Answers.UserDisplayName: Norris
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-15T16:09:49.787Z
Answers.Text: @Norris - that hack is good for a quick POC but for the real thing you want to add a separate js file. The miniforms get detached from the dom on document ready by caseView.js and then you won't be able to modify them, so ensure your script runs first.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-15T17:48:40.770Z
Answers.Text: Thanks!  I got my js file to load before CaseView via buildForm hook.  Now I can assign $('[name=edit_role_contact_id]').val('').data('group', 58) and get an alert of 58, even with on.'click' events after the page fully loads.  But it doesn't effect the actual filtering.  I've tried assigning data() with and without the val(''), and also tried #('[name=edit_role_contact_id]').val('').crmEntityRef(params); using the params that work in CaseView.js. I've tried 'group' (works in CV.js) and 'group_id'.  I must still be missing something...thoughts?
Answers.UserDisplayName: Norris
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-15T21:07:14.857Z
Answers.Text: $('[name=edit_role_contact_id]').data('api-params', {params: {group: 1}});
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-16T02:49:22.823Z
Answers.Text: Hmm, that should have worked but didn't. I think this patch fixes it: https://patch-diff.githubusercontent.com/raw/civicrm/civicrm-core/pull/6980.diff
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T15:41:45.580Z
Answers.LastActivityDate: 2015-04-27T14:12:00.233Z
Answers.LastEditDate: 2015-04-27T14:12:00.233Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>As of CiviCRM version 4.6 the contact autocomplete (aka entityRef) field provides the sort of filters you are requesting.</p>
  
  <p><img src="https://i.sstatic.net/ieQq3.png" alt="Add role dialog"></p>
  
  <p>When the autocomplete box opens you'll see a "Refine search..." option, which allows you to limit results by group, tag, contact type, and other filters.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T07:22:47.110Z
Answers.Text: That helps. But as a general aid in finding and creating contact relations, it only works when you *add* a role, not modifying etc. Also the person doing it need to know which group or tag etc. to use. I was looking for a way to define that group in the case type or something similar.
Answers.UserDisplayName: thoni56
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-22T13:29:19.003Z
Answers.LastActivityDate: 2015-04-22T13:29:19.003Z
Answers.UserDisplayName: Coleman
Body: <p>When I assign a case role to someone it seems like CiviCRM allows/requires me to search through the whole contact database. As there might be many matches for a search string it takes extra time to ensure that the one I assign is really the one I intended.</p>
  
  <p>In my organization only a few persons are actually possible targets for such an assignment, as I assume is the case in most constituents, thus only a few in the contact database should be possible to select on e.g. assignment of case responsible.</p>
  
  <p>Am I missing some configuration to make this happen? I know about permissions (which I so far have had no need for, "normal" contacts don't access our CiviCRM), are they related to this?</p>
  
  <p>On essence, I want the contacts to be searched when assigning a case role to be limited, e.g by a group, so a match can be found quicker and more unambiguous. How do I do that?</p>
  
Tags: <civicase>
Title: Limit the list of contacts to search when assigning a case role
ThreadText: # Limit the list of contacts to search when assigning a case role
  
  (Asked by: username_0 on 2015-04-22)
  
  When I assign a case role to someone it seems like CiviCRM allows/requires me to search through the whole contact database. As there might be many matches for a search string it takes extra time to ensure that the one I assign is really the one I intended.
  
  In my organization only a few persons are actually possible targets for such an assignment, as I assume is the case in most constituents, thus only a few in the contact database should be possible to select on e.g. assignment of case responsible.
  
  Am I missing some configuration to make this happen? I know about permissions (which I so far have had no need for, "normal" contacts don't access our CiviCRM), are they related to this?
  
  On essence, I want the contacts to be searched when assigning a case role to be limited, e.g by a group, so a match can be found quicker and more unambiguous. How do I do that?
  
  **Tags:** civicase
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-04-23. Score: 1 | Accepted answer
  
  The contact selector is an [EntityRef field](http://wiki.civicrm.org/confluence/display/CRMDOC/EntityRef+Fields). If you'd like to "enforce" a certain group or other filter on this field, you can do so with a small amount of custom code on your site.
  
  Modifying a form in CiviCRM depends on how the form is generated. Because this form is written in javascript, I recommend adding a custom js file to the CiviCase dashboard screen. It simply needs to add [data](https://api.jquery.com/data/) to the two fields (`edit_role_contact_id` and `add_role_contact_id`) that specifies the group\_id of your group.
  
  You can either use a custom module/plugin on your website or [create an extension](http://wiki.civicrm.org/confluence/display/CRMDOC/Create+a+Module+Extension) to add your javascript file using [CRM\_Core\_Resources](http://wiki.civicrm.org/confluence/display/CRMDOC/Resource+Reference) from [a hook](http://wiki.civicrm.org/confluence/display/CRMDOC/Hook+Reference). [hook\_civicrm\_caseSummary](http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseSummary) might be a good one, you wouldn't be using it for exactly its intended purpose but it fires on the right screen.
  
  > **Comments:**
  > **username_0**: Where do I read up on implementing such a custom addition? I am a seasoned programmer...  
  > **username_1**: I had given some doc links already but just edited the post to add more. Happy coding :)  
  > **username_0**: Ok, partially there. What JS object should I add the data to? How do I find out?  
  > **username_1**: Add it directly to the form elements in the dom. I gave you their names above.  
  > **username_2**: username_0, did you get this working?  If so, can you share what you did?  I want to do the same thing, and having an example would save me a lot of time.  Thanks!  
  > **username_2**: I can edit templates/CRM/Case/Form/CaseView.js to add "group, 58" to the params defining edit_role_contact_id, successfully filtering by the group, but putting my modified file into my template override directory doesn't change anything - should it?  I can't for the life of me figure out how to access the add_role_contact_id field from a separate javascript file.  I can attach data of ("group", 58) to other elements on the page and use alert() to echo them back, but doing so with $('#editCaseRoleDialog') or $('[name=edit_role_contact_id]') results in "undefined".  So close - what am I missing?  
  > **username_1**: @username_2 - that hack is good for a quick POC but for the real thing you want to add a separate js file. The miniforms get detached from the dom on document ready by caseView.js and then you won't be able to modify them, so ensure your script runs first.  
  > **username_2**: Thanks!  I got my js file to load before CaseView via buildForm hook.  Now I can assign $('[name=edit_role_contact_id]').val('').data('group', 58) and get an alert of 58, even with on.'click' events after the page fully loads.  But it doesn't effect the actual filtering.  I've tried assigning data() with and without the val(''), and also tried #('[name=edit_role_contact_id]').val('').crmEntityRef(params); using the params that work in CaseView.js. I've tried 'group' (works in CV.js) and 'group_id'.  I must still be missing something...thoughts?  
  > **username_1**: $('[name=edit_role_contact_id]').data('api-params', {params: {group: 1}});  
  > **username_1**: Hmm, that should have worked but didn't. I think this patch fixes it: https://patch-diff.githubusercontent.com/raw/civicrm/civicrm-core/pull/6980.diff  
  
  ---
  
  ### Answer by username_1 on 2015-04-22. Score: 2
  
  As of CiviCRM version 4.6 the contact autocomplete (aka entityRef) field provides the sort of filters you are requesting.
  
  ![Add role dialog](https://i.sstatic.net/ieQq3.png)
  
  When the autocomplete box opens you'll see a "Refine search..." option, which allows you to limit results by group, tag, contact type, and other filters.
  
  > **Comments:**
  > **username_0**: That helps. But as a general aid in finding and creating contact relations, it only works when you *add* a role, not modifying etc. Also the person doing it need to know which group or tag etc. to use. I was looking for a way to define that group in the case type or something similar.  
  
  ---
  
  