How to add a field in a form that allows selecting an instance of a many-to-many relationship?

I have two custom modules A and B with a many-to-many relationship between them. As expected there are subpanels at both ends of the relationship. It is now desired that in one of these modules in the creation or edition an instance of the module with which it is related can be selected in the form. An example of these is the case between contacts and accounts.

To this end, try creating relational fields following the example of contact and accounts public/legacy/modules/Contacts/vardefs.php

'account_name' =>
                 array(
                     'name' => 'account_name',
                     'rname' => 'name',
                     'id_name' => 'account_id',
                     'vname' => 'LBL_ACCOUNT_NAME',
                     'join_name' => 'accounts',
                     'type' => 'relate',
                     'link' => 'accounts',
                     'table' => 'accounts',
                     'isnull' => 'true',
                     'module' => 'Accounts',
                     'dbType' => 'varchar',
                     'len' => '255',
                     'source' => 'non-db',
                     'unified_search' => true,
                 ),
             'account_id' =>
                 array(
                     'name' => 'account_id',
                     'rname' => 'id',
                     'id_name' => 'account_id',
                     'vname' => 'LBL_ACCOUNT_ID',
                     'type' => 'relate',
                     'table' => 'accounts',
                     'isnull' => 'true',
                     'module' => 'Accounts',
                     'dbType' => 'id',
                     'reportable' => false,
                     'source' => 'non-db',
                     'massupdate' => false,
                     'duplicate_merge' => 'disabled',
                     'hideacl' => true,
                 ),

In public/legacy/custom/Extension/modules/A/Ext/Vardefs/custom_fields.php I reproduce the previous example like this

$dictionary['A']['fields']['b_name_c'] = [
     'name' => 'b_name_c',
     'rname' => 'name',
     'id_name' => 'b_id',
     'vname' => 'LBL_A_NAME_C',
     'join_name' => 'b',
     'type' => 'relate',
     'link' => 'b',
     'table' => 'b',
     'isnull' => 'true',
     'module' => 'b',
     'dbtype' => 'varchar',
     'len' => '255',
     'source' => 'non-db',
     'unified_search' => true
];

$dictionary['A']['fields']['b_id'] = [
     'name' => 'b_id',
     'rname' => 'id',
     'id_name' => 'b_id',
     'vname' => 'LBL_B_ID',
     'type' => 'relate',
     'table' => 'b',
     'isnull' => 'true',
     'module' => 'b',
     'dbType' => 'id',
     'reportable' => false,
     'source' => 'non-db',
     'massupdate' => false,
     'duplicate_merge' => 'disabled',
     'hideacl' => true
];

$dictionary['A']['fields']['b'] = [
     'name' => 'b',
     'type' => 'link',
     'relationship' => 'a_b',
     'link_type' => 'one',
     'source' => 'non-db',
     'vname' => 'LBL_B',
     'duplicate_merge' => 'disabled',
];

After repairing and rebuilding, I expected a script to be executed but this does not happen. The process ends successfully but without adding the new field that I hope to move to the editing form in order to achieve the expected behavior

Any idea how to achieve this? Thanks in advance

I don’t know, but maybe you could create a workflow :thinking:

Workflows

SuiteCRM Workflows Tutorial