Greetings, community! I am PHP programmer, new to SuiteCRM.
I have created the CNAE module:
Every account might have one CNAE, for that I created a field (relate type) in the Account:
I want to display this related filed on all Account’s view (details, create, edit, list, etc) with these CNAE’s fields in the following format:
"{$subclasse_id} {$subclasse} {$classe} {$grupo} {$divisao} {$secao}"
How can I achieve that?
pgr
2
Have a look at posts containing “customCode”, these are about customizing viewdefs to show fields like what you describe
@pgr I did that… no luck
Here is what I tried, but it’s returning error:
public/legacy/custom/modules/Accounts/metadata/listviewdefs.php
:
<?php
$listViewDefs ['Accounts'] = array (
//...
'CNAE_PRIMARIO_C' => array (
'type' => 'relate',
'default' => true,
'studio' => 'visible',
'label' => 'LBL_CNAE_PRIMARIO',
'id' => 'CNAE_CNAE_ID_C',
'link' => true,
'width' => '10%',
"customCode" => "{$SUBCLASSE_ID} {$SUBCLASSE} {$CLASSE} {$GRUPO} {$DIVISAO} {$SECAO}"
)
);
?>
public/legacy/custom/modules/Accounts/metadata/detailviewdefs.php
:
<?php
$viewdefs ['Accounts'] =
array (
'DetailView' =>
array (
'panels' =>
array (
'lbl_account_information' =>
array (
// ...
6 =>
array (
0 =>
array (
'name' => 'cnae_primario_c',
'studio' => 'visible',
'label' => 'LBL_CNAE_PRIMARIO',
"customCode" => "{$fields.subclasse_id.value} {$fields.subclasse.value} {$fields.classe.value} {$fields.grupo.value} {$fields.divisao.value} {$fields.secao.value}"
),
),
),
),
),
);
?>
pgr
4
You’re probably not referencing your fields correctly…
Try looking at them in Studio, for example, the field name in your screenshot above is cnae_primario_c
EDIT: I just asked ChatGPT
The idea is to run this once to see full list of all the fields available to you. Then you can choose the correct names.
@pgr I did a quick test using the code provided by ChatGPT
public/legacy/custom/modules/Accounts/metadata/detailviewdefs.php
:
// ...
array (
'name' => 'name',
'comment' => 'Name of the Company',
'label' => 'LBL_NAME',
"customCode" =>
"<ul>
{foreach from=$fields key=name item=value}
<li><strong>{$name}:</strong> {$value}</li>
{/foreach}
</ul>"
),
But it’s generating this warning Undefined variable $fields
logs/prod/prod.log
:
[2024-10-17 23:55:19] php.WARNING: Warning: Undefined variable $fields {"exception":"[object] (ErrorException(code: 0): Warning: Undefined variable $fields at /var/www/public/legacy/custom/modules/Accounts/metadata/detailviewdefs.php:206)"} []
[2024-10-17 23:55:19] php.WARNING: Warning: Undefined variable $name {"exception":"[object] (ErrorException(code: 0): Warning: Undefined variable $name at /var/www/public/legacy/custom/modules/Accounts/metadata/detailviewdefs.php:207)"} []
[2024-10-17 23:55:19] php.WARNING: Warning: Undefined variable $value {"exception":"[object] (ErrorException(code: 0): Warning: Undefined variable $value at /var/www/public/legacy/custom/modules/Accounts/metadata/detailviewdefs.php:207)"} []
rsp
6
Are these warnings displayed on the screen?
Try this one:
array (
'name' => 'name',
'comment' => 'Name of the Company',
'label' => 'LBL_NAME',
"customCode" =>
"<ul>
{if isset(\$fields) && count(\$fields) > 0}
{foreach from=\$fields key=name item=value}
<li><strong>{\$name}:</strong> {\$value}</li>
{/foreach}
{else}
<li>No fields available.</li>
{/if}
</ul>"
),