Answers.Body: <p>I don't think this is currently possible with the existing functionality. But you can attain this by custom fields with little customization using extension. What needs to be done is -</p>
  
  <ul>
  <li>Create a contact custom set from <code>Administer -&gt; Customise Data &amp; Screens -&gt; Custom Fields</code>.</li>
  <li>Add a single field. Eg. <code>Created By</code>. Make it searchable (Select <code>Is this Field Searchable?</code> to <code>Yes</code>     ).</li>
  <li>Create a simple extension using <a href="https://docs.civicrm.org/dev/en/master/extensions/civix/" rel="nofollow noreferrer">civix</a>.</li>
  <li>Write <a href="https://docs.civicrm.org/dev/en/master/hooks/hook_civicrm_post/" rel="nofollow noreferrer">post hook</a> and save a value for this field in DB </li>
  <li>Go to Advance Search and search it by using this field.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-07T11:03:24.720Z
Answers.Text: Thank you for the reply. Your method solves half of my problem. The thing is I want to search by current logged in user. Simply the Advanced search / Smart group should show contacts created by the current logged in user.
  So if user x logs in The smart group should show contacts xa, xb, xc
  But If user y logs in it should show ya, yb, yc as contacts in the smart group
Answers.UserDisplayName: nmeegama
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-07T11:09:23.710Z
Answers.Text: yes, I understand your requirement. This is what the posted answer can do with the extension. You need to write a little code inside the post hook which saves the logged in user id into this custom field after a contact is created. And then you can use this field in the advance search.
Answers.UserDisplayName: jitendra - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-07T12:08:08.273Z
Answers.Text: But still on the advanced search we would have to type in the logged in users ID right ?
  We can do the same in the Changelog section using the Added by field and type the created users email to search
  I want something like
  
  created id = <?php $_GET['cid'] ?>
  
  Something similar to contextual filters in Drupal
  Hope I am not confusing you
Answers.UserDisplayName: nmeegama
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-06T09:24:09.840Z
Answers.LastActivityDate: 2017-09-06T09:24:09.840Z
Answers.UserDisplayName: jitendra - fuzion
Answers.Body: <p>I solved this the following was
  I first installed the below extensions on civicrm</p>
  
  <ol>
  <li>Entity Settings Helper Extension</li>
  <li>Related Permissions Module</li>
  </ol>
  
  <p><a href="https://i.sstatic.net/aAkyQ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/aAkyQ.png" alt="enter image description here"></a></p>
  
  <p>Then I created a relationship</p>
  
  <ol>
  <li>GOTO /civicrm/admin/reltype?reset=1</li>
  <li>Click on Add Relationship Type and add the relationship. Make sure you check the Always Permission A to B check box
  <a href="https://i.sstatic.net/xXYUL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xXYUL.png" alt="enter image description here"></a></li>
  </ol>
  
  <p>The next step is to create a Drupal module that will add the above created relationship to the new contact and the creator of the contact. We need to just use on hook to get this done. The code has the relationship ID hard coded but it works :)</p>
  
  <p><code>
  /**
   * Implements hook_civicrm_post
   */
  function crc_civicrm_creator_relate_civicrm_post($op, $objectName, $objectId, &amp;$objectRef) {
    if (!civicrm_initialize()) {
      return;
    }</p>
  
  <p>if ($objectName == "Individual" &amp;&amp; $op == 'create') {
      global $user;
      $userObj = user_load($user->uid);
      // Get the email of the current logged in user
      $emailObj = civicrm_api3('Email', 'get', [
        'sequential' => 1,
        'email' => $userObj->mail,
      ]);
      //Create a relationship between the current user and the created
      // individual contact
      $result = civicrm_api3('Relationship ', 'create', [
        'sequential' => 1,
        'contact_id_a' => $emailObj['values'][0]['contact_id'],
        'contact_id_b' => $objectId,
        'relationship_type_id' => 11,
      ]);
    }
  }
  </code></p>
  
  <p>THATS IT. Now enable the module and create your contacts and you will also be able to search view and edit them.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-27T20:41:31.263Z
Answers.LastActivityDate: 2017-09-27T20:41:31.263Z
Answers.UserDisplayName: nmeegama
Body: <p>Basically what I need to do is search for contacts created by the <strong>current logged in user</strong>. I have tried the change log tab but that does not work for me because then it would be contacts created by user <strong><em>x</em></strong> which is not what I want. I don't know if this is possible. Please help.</p>
  
  <p>I need to create a smart group with this search criteria. My end goal is to use this smart group to give access to all users to view/edit the contacts they themselves created,</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-06T09:42:18.920Z
Comments.Text: Are you using Drupal? If you just want to display this stuff it might be possible with Drupal Views
Comments.UserDisplayName: mickadoo
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-06T11:12:03.563Z
Comments.Text: Yes I am using Drupal but I am bounded to use the civicrm User interface
Comments.UserDisplayName: nmeegama
Tags: <search><permissions><smartgroups><acl>
Title: How to use advanced search to search contacts created by logged in user
ThreadText: # How to use advanced search to search contacts created by logged in user
  
  (Asked by: username_0 on 2017-09-06)
  
  Basically what I need to do is search for contacts created by the **current logged in user**. I have tried the change log tab but that does not work for me because then it would be contacts created by user ***x*** which is not what I want. I don't know if this is possible. Please help.
  
  I need to create a smart group with this search criteria. My end goal is to use this smart group to give access to all users to view/edit the contacts they themselves created,
  
  **Tags:** search, permissions, smartgroups, acl
  
  > **Comments:**
  > **username_1**: Are you using Drupal? If you just want to display this stuff it might be possible with Drupal Views  
  > **username_0**: Yes I am using Drupal but I am bounded to use the civicrm User interface  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-09-06. Score: 1
  
  I don't think this is currently possible with the existing functionality. But you can attain this by custom fields with little customization using extension. What needs to be done is -
  
  * Create a contact custom set from `Administer -> Customise Data & Screens -> Custom Fields`.
  * Add a single field. Eg. `Created By`. Make it searchable (Select `Is this Field Searchable?` to `Yes` ).
  * Create a simple extension using [civix](https://docs.civicrm.org/dev/en/master/extensions/civix/).
  * Write [post hook](https://docs.civicrm.org/dev/en/master/hooks/hook_civicrm_post/) and save a value for this field in DB
  * Go to Advance Search and search it by using this field.
  
  > **Comments:**
  > **username_0**: Thank you for the reply. Your method solves half of my problem. The thing is I want to search by current logged in user. Simply the Advanced search / Smart group should show contacts created by the current logged in user. So if user x logs in The smart group should show contacts xa, xb, xc But If user y logs in it should show ya, yb, yc as contacts in the smart group  
  > **username_2**: yes, I understand your requirement. This is what the posted answer can do with the extension. You need to write a little code inside the post hook which saves the logged in user id into this custom field after a contact is created. And then you can use this field in the advance search.  
  > **username_0**: But still on the advanced search we would have to type in the logged in users ID right ? We can do the same in the Changelog section using the Added by field and type the created users email to search I want something like  created id = <?php $_GET['cid'] ?>  Something similar to contextual filters in Drupal Hope I am not confusing you  
  
  ---
  
  ### Answer by username_0 on 2017-09-27. Score: 1
  
  I solved this the following was
  I first installed the below extensions on civicrm
  
  1. Entity Settings Helper Extension
  2. Related Permissions Module
  
  [![enter image description here](https://i.sstatic.net/aAkyQ.png)](https://i.sstatic.net/aAkyQ.png)
  
  Then I created a relationship
  
  1. GOTO /civicrm/admin/reltype?reset=1
  2. Click on Add Relationship Type and add the relationship. Make sure you check the Always Permission A to B check box
     [![enter image description here](https://i.sstatic.net/xXYUL.png)](https://i.sstatic.net/xXYUL.png)
  
  The next step is to create a Drupal module that will add the above created relationship to the new contact and the creator of the contact. We need to just use on hook to get this done. The code has the relationship ID hard coded but it works :)
  
  `/**
  * Implements hook_civicrm_post
  */
  function crc_civicrm_creator_relate_civicrm_post($op, $objectName, $objectId, &$objectRef) {
  if (!civicrm_initialize()) {
  return;
  }`
  
  if ($objectName == "Individual" && $op == 'create') {
  global $user;
  $userObj = user\_load($user->uid);
  // Get the email of the current logged in user
  $emailObj = civicrm\_api3('Email', 'get', [
  'sequential' => 1,
  'email' => $userObj->mail,
  ]);
  //Create a relationship between the current user and the created
  // individual contact
  $result = civicrm\_api3('Relationship ', 'create', [
  'sequential' => 1,
  'contact\_id\_a' => $emailObj['values'][0]['contact\_id'],
  'contact\_id\_b' => $objectId,
  'relationship\_type\_id' => 11,
  ]);
  }
  }
  
  THATS IT. Now enable the module and create your contacts and you will also be able to search view and edit them.
  
  
  ---
  
  