Module Related List¶
One module could be associated with multiple records of other module that is displayed under “More Information” tab on Detail View.
The example given below describes the way of creating a relation between a Payslip and Accounts module:
include_once('vtlib/Vtiger/Module.php');
$moduleInstance = Vtiger_Module::getInstance('Payslip');
$accountsModule = Vtiger_Module::getInstance('Accounts');
$relationLabel = 'Accounts';
$moduleInstance->setRelatedList(
$accountsModule, $relationLabel, Array('ADD','SELECT')
);
With this you can Add one or more Accounts to Payslip records. To drop the relation between the modules use the following:
$moduleInstance->unsetRelatedList($targetModuleInstance);
About setRelatedList API¶
Vtiger_Module->setRelatedList(<TARGET MODULE>[, <HEADER LABEL>, <ALLOWED ACTIONS>, <CALLBACK FUNCTION NAME>]);
<TARGET MODULE> |
Module name to which relation is being setup. |
<HEADER LABEL> |
Optional (default = <TARGET MODULE>) Label to use on the More Information related list view. |
<ALLOWED ACTIONS> |
ADD or SELECT (default = false) What buttons should be shown in the related list view while adding records. |
<CALLBACK FUNCTION NAME> |
Optional (default = get_related_list) The function should be defined in the <SOURCE MODULE> class. This should generate the listview entries for displaying. |
Note
This API will create an entry in the vtiger_crmentityrel table to keep track of relation between module records. Standard modules available in vtiger CRM handles the relation in separate tables and performs the JOIN to fetch data specific to each module. This is an attempt to achieve generic behavior. You can write custom call back functions to handle related list queries that will meet your requirements.
Limitations¶
Following limitations apply for the related list APIs
1. Standard module class variables are not set as required by the get_related_list vtlib module API. Case handling should be handled @function vtlib_setup_modulevars in include/utils/VtlibUtils.php
2. get_related_list API added to module class does not handle JOIN on tables where some modules like (Accounts) store information hence complete details are not fetched in the Related List View. (Example Sorting on the city field on related list view will fail if dieOnError is true)