简体   繁体   中英

SugarCRM Smarty Code in Listviewdefs

I'm trying to use Smarty PHP for custom functionality in the ListView (custom/modules/Leads/metadata/listviewdefs.php) of SugarCRM (6.5.3).

This works fine:

'customCode' => '{$LD_ASSUMED_SUGAR_ACCOUNT_ID_C}',

And so does this:

'customCode' => '{$ACCOUNT_NAME}',

However this just outputs the code (brackets and all) in the List (but with Account name substituted for the correct value):

'customCode' => '{if $LD_ASSUMED_SUGAR_ACCOUNT_ID_C}{$ACCOUNT_NAME}{/if}',

What am I doing wrong!?

I don't think you can achieve the same result you are looking for in ListView like you can in EditView & DetailView. One way to go about this is to add a non-db field to Leads vardefs and use a logic hook to handle conditional formatting.

Create a new vardef:

/custom/Extension/modules/Cases/Ext/Vardefs/my_listview_value_c.php

<?php
    $dictionary['Lead']['fields']['my_listview_value_c'] = array(
      'name' => 'my_listview_value_c',
      'vname' => 'LBL_MY_LISTVIEW_VALUE_C',
      'type' => 'varchar',
      'len' => '255',
      'source' => 'non-db',
    );
?>

Create the logic hook:

/custom/modules/Leads/ListViewLogicHook.php

<?php
class ListViewLogicHook {

    public function getListValue(&$bean, $event, $arguments) {
        if ($bean->ld_assumed_sugar_account_id_c) {
            $bean->my_listview_value_c = $bean->account_name;
        } else {
            // Whatever you'd like
        }
    }
}

Add the logic hook entry:

// position, file, function
$hook_array['process_record'] = Array();
$hook_array['process_record'][] = Array(1, 'Conditional formatting in a listview column', 'custom/modules/Leads/ListViewLogicHook.php','ListViewLogicHook','getListValue');

Finally, in your listviewdefs add the new column:

'MY_LISTVIEW_VALUE_C' => 
    array (
        'width' => '10%',
        'label' => 'LBL_MY_LISTVIEW_VALUE_C',
        'default' => true,
 ),

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM