1

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

3
  • 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. Commented 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
    Commented Oct 28, 2019 at 10:59
  • See civicrm.stackexchange.com/a/3842/12 Commented Oct 28, 2019 at 12:11

1 Answer 1

0

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.