Search many to many relationship field

Hi, another way to realise this is by vardefs:

  1. Create the file

custom/Extension/modules/Project/Ext/Vardefs/account_name.php

with contents

<?php

$dictionary['Project']['fields']['account_name'] = array (
		'name' => 'account_name',
		'rname' => 'name',
		'id_name' => 'account_id',
		'vname' => 'LBL_ACCOUNT_NAME',
		'type' => 'relate',
		'link' => 'accounts',
		'table' => 'accounts',
		'isnull' => 'true',
		'module' => 'Accounts',
		'dbType' => 'varchar',
		'source' => 'non-db',
		'studio' => array('editview' => false, 'detailview' => false, 'listview' => false, 'dashlet' => false, 'popuplist' => false),
	);
  1. Create the file

custom/Extension/modules/Project/Ext/Language/en_us.account_name.php

with contents

<?php

$mod_strings['LBL_ACCOUNT_NAME'] = 'Account Name';
  1. Do a Admin -> Repair -> Quick Repair and Rebuild

Afterwards you can go into studio and add the field in your Quick Filter and/or Advanced Filter.

The field in the filter is a relate field, from which you can search and select existing Accounts. In case you need a text field (so you can use wildcards), then, after you have added the field to your filter, edit:

custom/modules/Project/metadata/searchdefs.php

and locate the account_name field:

      'account_name' =>
      array (
        'type' => 'relate',
        'link' => true,

Modify ‘type’ from ‘relate’ to ‘varchar’, so it becomes

     'account_name' =>
      array (
        'type' => 'varchar',
        'link' => true,

and save.

Afterwards to a Admin -> Repair -> Quick Repair and Rebuild.

2 Likes