0 Comments | 0 Shares | Urdhva Tech

Today I came across a requirement where client wanted to see Contacts related to a Case at Account's level.

That means, if I open an account, and it has a Case linked to it, I should be able to see the Contacts related to that Case right in the same subpanel.

Few steps and done!

Step 1: Is to create a non-db field in Cases module. Create a file in custom/Extension/modules/Cases/Ext/Vardefs/<any_name>.php and write following code.

$dictionary["Case"]["fields"]["contacts_non_db"] = array (
    'name' => 'contacts_non_db',
    'type' => 'varchar',
    'default'=> '',
    'vname' => 'LBL_CONTACTS',
    'reportable' =>true,
    'source' => 'non-db'

Step 2: Place the field in subpanel. Go to Admin > Studio > Accounts > Subpanels > Cases and press Save.

We cannot find non-db fields here, so we need to change it from file manually.

This will create a file under custom/modules/Cases/metadata/subpanels/Account_subpanel_cases.php

Open that and add following code where you want to see your field.

'contacts_non_db' =>
  array (
    'name' => 'contacts_non_db',
    'vname' => 'LBL_CONTACTS',
    'width' => '30%',
    'default' => true,
    'sortable' => false,
Step 3: Now we need to give the value to the field. We need to create logic hook to process and display contacts.

Check if you have logic_hooks.php under folder custom/modules/Cases? If no, create one and add following code.

$hook_array['process_record'][] = Array(2, 'Show contacts', 'custom/modules/Cases/showContacts.php','showContactsC', 'showContactsF'); 

Then create file at custom/modules/Cases/showContacts.php and add following code in there.

class showContactsC{
    function showContactsF($bean, $event, $args){
        // fetching related contacts
       $oContacts = $bean->get_linked_beans('contacts', 'Contacts');
        $contact = '';
        foreach($oContacts as $iContacts => $oContact)
            if($iContacts < 3)
                $contact .= ",<a href = 'index.php?action=DetailView&module=Contacts&record=".$oContact->id."'>".$oContact->full_name."</a>";
                $contact .= ',...';
        $bean->contacts_non_db = substr($contact,1);
There you are! Do Quick Repair and Rebuild! The result should be in front of your eyes!

P.S. To optimize the view I have shown only first 3 Contacts, if you want to show all Contacts, remove condition on $iContacts.

Download attachments:
  • No Comments Found.
Post your comment