How do I add 3 custom fields to a many to many relationship for a custom module (in its linking table essentially)?
Iâve created a samples module that has a many to many relationship to products. I need to be able to define a quantity, lot, and a chop boolean field that is part of each linked / created product relationship from the sample.
Thus, in the products area below, when a product is linked or created, I need those three additional fields to show up there as part of the relationship and be editable. Is that possible?
Is there a way to do this? Googleâs AI has given me two different processes to follow, but it doesnât seem right (doesnât match the structure of suitecrm8 exactly).
Googleâs AI says:
Adding additional fields to a many-to-many relationship in SuiteCRM requires direct modification of the relationship metadata and is not achievable through Studio or Module Builder. This process involves several steps:
- Define the new fields in the relationship metadata:
- Locate the relevant metadata file for your many-to-many relationship. This file is typically found in
custom/metadata/and is named after your relationship (e.g.,fp_events_contactsMetaData.phpfor a relationship betweenFP_eventsandContacts).- Within this file, locate the
$dictionaryarray for your relationship and add your custom field definitions to thefieldsarray. For example, to add adate_cancelledfield of typedate:Code
$dictionary['fp_events_contacts']['fields']['date_cancelled'] = array( 'name' => 'date_cancelled', 'type' => 'date', 'vname' => 'LBL_DATE_CANCELLED', // Label for the field 'massupdate' => false, 'no_default' => false, 'comments' => '', 'help' => '', 'importable' => 'true', 'duplicate_merge' => 'disabled', 'duplicate_merge_dom_value' => '0', 'audited' => false, 'reportable' => true, 'unified_search' => false, 'merge_filter' => 'disabled', 'calculated' => false, 'size' => '20', );
Add the field to the subpanel layout:
- Navigate to the subpanel definition file for the module where you want to display the field (e.g.,
custom/Extension/modules/FP_events/Ext/Layoutdefs/fp_events_contacts.php).- Add your new field to the
columnsarray within the subpanel definition.Create a custom language string (LBL) for the field:
- Create or modify a language file (e.g.,
custom/Extension/modules/FP_events/Ext/Language/en_us.lang.php) and add a label for your new field.Code
$mod_strings['LBL_DATE_CANCELLED'] = 'Date Cancelled';
- Perform a Quick Repair and Rebuild:
- Go to Admin > Repair and execute âQuick Repair and Rebuildâ to apply your changes to the database and clear the cache.
After these steps, the custom field will be part of the relationship table and visible in the corresponding subpanel. You can then populate and manage the data for this field.
And also says:
Adding custom fields to a many-to-many relationship in SuiteCRM 8.9 requires manual code modifications as it is not possible to do directly through Studio or Module Builder. You cannot manipulate the relationship tables using the standard admin interfaces.
The process involves modifying several specific metadata and vardef files to define the new field in the relationshipâs junction table and then expose it in the user interface.
Steps for Implementation
The implementation process involves several steps to define the field in the database and make it visible in the UI:
- Define the field in metadata: Add the custom field definition to the relationship metadata file (
custom/metadata/<relationship_name>MetaData.php) within the$dictionaryarray. Then, run a Quick Repair & Rebuild to create the field in the database junction table.- Define the field in Vardefs: Create a new Vardefs file (
custom/Extension/modules/<ModuleName>/Ext/Vardefs/) and define the custom field, including a ârelateâ type field, a definition for the value type withsourceset to'non-db', and a definition for the fieldâs ID.* Define the field in subpanel layoutdefs: Add the new field to the'list_fields'array in the subpanel layoutdefs file (custom/modules/<ModuleName>/metadata/subpanels/).* Add the field label: Include the display label for the new field in a custom language file (custom/Extension/application/Ext/Language/en_us.<ModuleName>.php).* Perform a final Quick Repair & Rebuild: Run another Quick Repair & Rebuild from the Admin panel to make the new fields functional and visible in the subpanel.Alternative Approach (Workaround)
As an alternative to manual coding, you can create an intermediate custom module (a junction module). This new module can have many-to-one relationships with the original modules, allowing you to easily add custom fields via Studio.

