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;

I want to replace 190 with a code that grabs the contact ID of that current users relationship.

Your help is much appreciated.


  • 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. Oct 24, 2019 at 4:59
  • @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.
    – Moe
    Oct 28, 2019 at 10:59

1 Answer 1


This code worked for me:

$contactId = CRM_Utils_Request::retrieve('cid', 'Positive');

Not the answer you're looking for? Browse other questions tagged or ask your own question.