Answers.Body: <p>This code worked for me:</p>
  
  <pre><code>$contactId = CRM_Utils_Request::retrieve('cid', 'Positive');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-28T13:39:00.273Z
Answers.LastActivityDate: 2019-10-28T13:39:00.273Z
Answers.UserDisplayName: Moe
Body: <p>I want to display Contact B ID of a relationship for the current contact. I am building a hook and this is my code so far.</p>
  
  <pre><code>if ( $formName == 'CRM_Contactlayout_Form_Inline_ProfileBlock') {
          if ($form == CRM_Core_Action::ADD) {
              $ID= '190';
              $defaults['custom_189'] = $ID;
              $form-&gt;updateElementAttr('custom_189',array('readonly'));
      }
  </code></pre>
  
  <p>I want to replace 190 with a code that grabs the contact ID of that current users relationship.</p>
  
  <p>Your help is much appreciated.</p>
  
  <p>Thanks</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-24T04:59:05.493Z
Comments.Text: Please clarify: Is the "current user" the logged in contact, or the contact being viewed?  Which hook is this - looks like `buildForm`, but I can't be sure?  That will matter for getting the current user.  Finally - have you looked at API Explorer (**Support » Developer » API Explorer**)?  Ultimately you'll be using the `Relationship.get` API, and the API Explorer will generate the code you need.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-28T10:59:10.147Z
Comments.Text: @JonG-MegaphoneTech - I want to get the ID of the contact being viewed and i have used the API Explorer i got the code ready but i need the id of the contact being viewed.
Comments.UserDisplayName: Moe
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-28T12:11:22.993Z
Comments.Text: See https://civicrm.stackexchange.com/a/3842/12
Comments.UserDisplayName: Jon G - Megaphone Tech
Tags: <custom-fields><relationships><hooks>
Title: Get Contact id from Relationship to use in a Hook
ThreadText: # Get Contact id from Relationship to use in a Hook
  
  (Asked by: username_0 on 2019-10-23)
  
  I want to display Contact B ID of a relationship for the current contact. I am building a hook and this is my code so far.
  
  ```
  if ( $formName == 'CRM_Contactlayout_Form_Inline_ProfileBlock') {
          if ($form == CRM_Core_Action::ADD) {
              $ID= '190';
              $defaults['custom_189'] = $ID;
              $form->updateElementAttr('custom_189',array('readonly'));
      }
  
  ```
  
  I want to replace 190 with a code that grabs the contact ID of that current users relationship.
  
  Your help is much appreciated.
  
  Thanks
  
  **Tags:** custom-fields, relationships, hooks
  
  > **Comments:**
  > **username_1**: Please clarify: Is the "current user" the logged in contact, or the contact being viewed?  Which hook is this - looks like `buildForm`, but I can't be sure?  That will matter for getting the current user.  Finally - have you looked at API Explorer (**Support » Developer » API Explorer**)?  Ultimately you'll be using the `Relationship.get` API, and the API Explorer will generate the code you need.  
  > **username_0**: @username_1 - I want to get the ID of the contact being viewed and i have used the API Explorer i got the code ready but i need the id of the contact being viewed.  
  > **username_1**: See https://civicrm.stackexchange.com/a/3842/12  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-10-28. Score: 0 | Accepted answer
  
  This code worked for me:
  
  ```
  $contactId = CRM_Utils_Request::retrieve('cid', 'Positive');
  
  ```
  
  
  ---
  
  