Related Field - Search

Hi all,

I extended the Calls module by a ID field pae_contact_id, linked to the Contacts Module. (see code below of the pae_vardef)

Additional I want to display & search the Contact Name and Country in the Calls List View.

Displaying the data works, but when trying to search the Country, I just get a list of all Contacts to filter on a single Contact:

What do I need to change to be able to search for e.g. all Calls where the Contact Country is "DE"

Many thanks for your help :)

Sven

// custom/Extension/modules/Calls/Ext/Vardefs/pae_vardefs.php 

$dictionary['Call']['fields']['pae_contact_id'] = array(
    'name' => 'pae_contact_id',
    'vname' => 'LBL_PAE_CONTACT_ID',
    'type' => 'id',
);

$dictionary['Call']['fields']['pae_contact_name'] = array(
    'name' => 'pae_contact_name',
    'vname' => 'LBL_PAE_CONTACT_NAME',
    'rname' => 'name',
    'type' => 'relate',
    'id_name' => 'pae_contact_id',
    'source' => 'non-db',
    'link' => 'pae_contact_link',
    'sort_on' => array('name',),
    'module' => 'Contacts',
    'table' => 'contacts',
    'audited' => true,
);

$dictionary['Call']['fields']['pae_contact_country'] = array(
    'name' => 'pae_contact_country',
    'vname' => 'LBL_PAE_CONTACT_COUNTRY',
    'rname' => 'primary_address_country',
    'type' => 'relate',
    'id_name' => 'pae_contact_id',
    'source' => 'non-db',
    'link' => 'pae_contact_link',
    'sort_on' => array('name',),
    'module' => 'Contacts',
    'table' => 'contacts',
    'audited' => true,
    'readonly' => true,
);


$dictionary['Call']['fields']['pae_contact_link'] = array(
    'name' => 'pae_contact_link',
    'type' => 'link',
    'relationship' => 'pae_rel_contact',
    'vname' => 'LBL_PAE_CONTACT_NAME',
    'source' => 'non-db',
);

$dictionary['Call']['relationships']['pae_rel_contact'] = array(
    'lhs_module' => 'Contacts',
    'lhs_table' => 'contacts',
    'lhs_key' => 'id',
    'rhs_module' => 'Calls',
    'rhs_table' => 'calls',
    'rhs_key' => 'pae_contact_id',
    'relationship_type' => 'one-to-many',
);

Parents
  • Hi Sven,

    You can do this by adding custom filters on the Contact ID in the calls module. Please go through Filters and Filter Examples in SugarCRM documentation. It is very clearly explained in this documentation on how to create custom filters in SugarCRM.

    Hope this helps you:)

    Thank you,

    Poojitha K

  • Hi Poojitha,

    Thanks for your help, I read these documents, but I think you got me wrong.

    When clicking on this filter on Calls List View:

    I get this Search and Select, with all Contacts listed and can select one or multiple Contacts, whose calls are then shown in the Calls List view.

    But I would like to have the Countries selectable there, like in the Contacts List View, and then get all Calls where the Contacts are in the specified countries.

  • Sven,

    The issue you have is that in your Vardefs file the fields you are specifying to be available to view in the Contact record (Name and Country) are only pseudo fields, they are not held in the Calls module so cannot be used for filtering. Only the related id is held and it is this that is available to filter on by Contact. A field needs to be "real" on a module to allow in-module filtering to work, the filter cannot build the query from related fields in the method you are hoping.

    All is not lost however, I think you can achieve what you want by adding the field to filter on as a proper custom field in the Calls module and then making it calculated based on the related Contact.

    Create a new field (you can do it all in Studio) on Calls called, for example, contact_primary_country, and check the box to make it calculated. Then open the formula builder and use the Related Field button to navigate via the related Contact to the address_country field you wish to store. This will set the field properly on the Call record when you have chosen a related Contact and allow you to use it in the filter search options.

    If your Contacts module has been adjusted to make the Country fields in the addresses based on a drop-down (the technique for this can be found in the Sugar docs) then I'm afraid that the options will not copy across to the filters if you use the above method as you cannot make a drop-down field calculated. If this is the case, and you want the options available on the Calls filter, then you will have to make the new custom field a type of drop-down, give it the same options as the related Contact field and then use a before_save logic hook to set the value.

    Whichever of these you use, you do not need the new custom field to be available on the record view, it will calculate / set via logic hook fine anyway. You will need to add it to the Search options and probably also the List View options in order to make it useful though.

    Hopefully this is what you are after.

    Thanks,

    JH.

  • Hi Sven,

    You can do as @John Hawkins suggested. It is one of the ways how we can achieve it to filter the records based on related module data.

    You can also create a simple report in the Calls module by adding a filter for the contact country field.

    Thanks,

    Poojitha K

Reply Children
No Data