How to Display a Custom Field from Accounts in Advanced Filter of Opportunities?

Hi everyone,

I have created a custom field (nif_c) in the Accounts module, and I need to display it as a filter in the Advanced Search of Opportunities.

Context:

• In SuiteCRM, Opportunities are already related to Accounts (each Opportunity has an associated Account).

• The field nif_c exists in Accounts and works correctly there.

• I want to use this field as a search filter in Opportunities, so users can filter opportunities based on the nif_c of the related Account.

What I’ve Tried So Far:

  1. Added the field to searchdefs.php of Opportunities:
'account_nif_c' => 
array (
    'type' => 'relate',
    'label' => 'LBL_ACCOUNT_NIF',
    'id' => 'account_id',
    'link' => true,
    'module' => 'Accounts',
    'table' => 'accounts',
    'rname' => 'nif_c',
    'default' => true,
    'width' => '10%',
),
  1. Created a custom Vardef for Opportunities in /custom/Extension/modules/Opportunities/Ext/Vardefs/custom_nif_c.php:
<?php
$dictionary["Opportunity"]["fields"]["account_nif_c"] = array(
    'name' => 'account_nif_c',
    'rname' => 'nif_c', // Field from Accounts
    'id_name' => 'account_id',
    'vname' => 'LBL_ACCOUNT_NIF',
    'type' => 'relate',
    'table' => 'accounts',
    'module' => 'Accounts',
    'source' => 'non-db',
    'link' => 'accounts',
);
?>
  1. Ran a Quick Repair & Rebuild in SuiteCRM.

  2. Cleared the cache and restarted Apache.

Problem:

• After adding this, the field does not appear in the Advanced Search of Opportunities.

• In some cases, adding the custom file caused all fields to disappear from the Opportunities module.

• There are no syntax errors in the PHP files.

Question:

How can I properly add a custom field from Accounts (nif_c) as a filter in the Advanced Search of Opportunities without breaking other fields?

Any help or insights would be greatly appreciated!

Thanks in advance! :rocket:

I’m not sure what you mean by “Advanced Search” where is that?

Are you talking about here? If so, you don’t need custom code just add it in studio.

Try if you can add it from the studio.

Admin → Studio → Opportunities → Layouts → Filter → Advance Filter

Yes, it’s this advanced filter. The problem is that the custom fields added from Studio cannot be displayed there unless forced in the code. Additionally, the field belongs to Account, not Opportunities.

The problem is that the custom fields added from Studio cannot be displayed there unless forced in the code. Additionally, the field belongs to Account, not Opportunities. Vardeffs

I dont believe thats the case. You can add custom fields to filter on. You cannot however add fields from accounts to filter opportunities. The fields have to be from the same module.

In tha past, I’ve created non db fields for opps that get populated based on the value from accounts by either before save hook or a process record hook. Then I can filter on the value in opps. You cannot directly filter on a field from another module.

I’ve just tested and added a custom field from studio to module filter: