Show related module fields in other module

Hello good afternoon. We have a SuiteCRM 7.11.8 where we have contacts related to products. Relationships can be viewed from each of both modules. What we need to do is show the related products of a contact as fields of the contact’s file, not being necessary to go to where the related module is and have to open it. Is this possible?. Thank you.

Regards.

Hi, what kind of relationship did you create between contacts and products? one-to many? many-to-one? many-to-many?

In case one-to many and many-to-many, you should see a subpanel with products in the contacts module. Many-to-one doesn’t make sense to me, because a contact then could only refer to a single product.

Can you make a screenshot of your contacts view?

@digitecmedia
You can’t do it because in SuiteCRM broken field type “collection”. But you can take commits files for upgrade from: https://github.com/salesagility/SuiteCRM/pull/8341 . There is repair this field type. After that you can add dynamic fields table from one module to any another module.

Hello Janisero, thanks for your reply. I created you 3 screen captures.
At screencapture1 you can see the Contact details with many custom fields I created.
At screencapture2 you can see the products related module to Contacts.
My goal is to show fields from related product at Contact details. It’s to say, I need to show a field like “CÓDIGO FARMACIA” that belongs to product module, at a field inside Contact details (screencapture1).

The other goal is: when I need to add a new related product to contact, I click on select and appears a screen like screencapture3. I need to show fields from contact in the search result grid. Now at result grid only appears fields from products, but I need to show data from related contacts of each product.

Do you know if I can do that anyway?.

Thanks a lot for your help.

Hello. Can you help me with this?. I will pay for it.

Kind regards.

Hi,

if a contact has multiple products:
then you would need to add multiple fields for Codigo Farmacia in your view, depending on the nr. of related products. This is a use case that is not support by SuiteCRM by default, because for this you have your subpanel below, containing all info concerning the related products. Why exactly do you need this information at the top of your screen?

If a contact always only has one product:
then your relationship setup should have been many-to-one (many contacts to one product)

Thanks for your reply. Right now relationship is many-to-many, but no one contact has more tan one product. So, is like relationship was many-to-one.

The most important for me is at point to search a product (farmacia) to relate it to contact, show fields from contact related to product:

User searches a pharmacy (product) to relate it to a contact. User can search the pharmacies by many fields, but we need to search a pharmacy thru the name of contact related with it. Or show the name field at pharmacies (products) search results.

Thanks a lot.

Kind regards.

Hello again. Can I do thru Worflows?. I created a custom field at Contact called “product name” that belongs to custom module “Propietario de”. How I can make a Worflow to copy all products name to custom field “product name” of all contacts?. Thanks.

Kind regards.

Hi,

I think you should first create your relationship as many contacts to one product.

To display fields of the product to contacts, you can either use the excellent work of @p.konetskiy (collection fields) or add so called “vardef” files to your installation. These vardef files can also enable you to search for products with the contact as search criteria.

I’d advise you to first change the relationship to many-to-one, I can then give you advise on the vardef files, preferably on a test installation.

Hello Jansiero, I will try it. Thanks.

Kins regards.

Hola @digitecmedia,

After creating the relationship as many contacts to one product, you can go into studio and add the products field to year Contacts Editview, Detailview etc.

When you also want to show the field Código Farmacia of the products in your contacts detailview, you will need to create this field by vardefs as describe in:

Specifically for your case (please first do this on a test environment):

Create the file:

custom/Extension/modules/AOS_Products/Ext/Vardefs/pharmacy_code.php

with contents

<?php

$dictionary['AOS_Products']['fields']['pharmacy_code'] = array (
    'name' => 'pharmacy_code',
    'vname' => 'LBL_PHARMACY_CODE',
    'type' => 'varchar',
    'len' => 60,
    'audited' => true,
    'unified_search' => true,
    'merge_filter' => 'enabled',
    'reportable' => '1',
    'importable' => 'true',
  );

Create the file

custom/Extension/modules/AOS_Products/Ext/Language/en_us.pharmacy_code.php

With contents:

<?php
$mod_strings['LBL_PHARMACY_CODE'] = 'Pharmacy Code';

For the spanish translation, also create the file:

custom/Extension/modules/AOS_Products/Ext/Language/es_es.pharmacy_code.php

with contents:

<?php
$mod_strings['LBL_PHARMACY_CODE'] = 'Código farmacia';

Create the file:

custom/Extension/modules/Contacts/Ext/Vardefs/product_pharmacy_code.php

with contents:

<?php
$dictionary['Contact']['fields']['aos_products_contacts_1']['join_link_name'] = 'contacts_aos_products_link';
$dictionary['Contact']['fields']['aos_products_contacts_1']['join_name'] = 'aos_products_link';

$dictionary['Contact']['fields']['products_pharmacy_code'] = array (
		'name' => 'products_pharmacy_code',
		'rname' => 'pharmacy_code',
		'id_name' => 'aos_products_contacts_1aos_products_ida',
		'vname' => 'LBL_PRODUCTS_PHARMACY_CODE',
		'join_name'=>'aos_products_link',
		'join_link_name'=>'contacts_aos_products_link',
		'type' => 'relate',
		'link' => 'aos_products_contacts_1',
		'table' => 'aos_products',
		'isnull' => 'true',
		'module' => 'AOS_Products',
		'dbType' => 'varchar',
		'source' => 'non-db',
		'unified_search' => true,
		'massupdate' => false,
		'studio' => array('detailview' => 'true'),
		'inline_edit' => false,
	);

The values for:

  • field name: aos_products_contacts_1
  • id_name: aos_products_contacts_1aos_products_ida
  • link: aos_products_contacts_1

need to correspond to the ones described in the existing file:

custom/Extension/modules/Contacts/Ext/Vardefs/aos_products_contacts_1_Contacts.php

Create the file:

custom/Extension/modules/Contacts/Ext/Language/en_us.products_pharmacy_code.php 

with contents:

<?php
$mod_strings['LBL_PRODUCTS_PHARMACY_CODE'] = 'Pharmacy Code';

For the spanish translation, also create

custom/Extension/modules/Contacts/Ext/Language/es_es.products_pharmacy_code.php 

with contents:

<?php
$mod_strings['LBL_PRODUCTS_PHARMACY_CODE'] = 'Código farmacia';

Do a Admin - Repair - Quick Repair and Rebuild, scroll down and make sure to click on execute to execute the query.

Afterwards the new field Código farmacia is available in the edit, detail and listviews of the products module, as well as in the detail, and listviews of the contacts module.

To migrate the field values of the previously created código farmacia field in studio, execute a query like this:

update aos_products as p, aos_products_cstm as pc set p.pharmacy_code = pc.codigo_farmacia_c where p.id = pc.id_c;

After successful migration you can then remove the código farmacia field previously created in studio.