Shorten/truncate contents of field in subpanel

Does anyone know how can I reduce the number of characters displayed in the entries in a column of a subpanel?

This probably requires a bit of explanation so please bear with me.

I have a field that is a concatenation of 3 other fields, including the GUID generated by SuiteCRM. I use this field to be the unique name for a custom module. In order to provide a clickable link in subpanels or list views. Since most of the actual “name” is nonsense characters, I shorten it in the module’s List View with a “process_record” logic hook and the code:

<?php
if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}
class truncateNameDisplay {
    function shortenNameFieldLength( $fundBean , $event , $arguments ){
        $fundBean->name = substr( $fundBean->name , 0 , 8 );
    }
}

This does NOT permanently change the name; it just shortens it for display in the List View.

So this works fine for the List View in teh module itself, but I want to do the same for subpanels pointing to this custom module from other modules, Like Contacts and Accounts.

The field that displays this “name” is linkable so uses the

"'widget_class' => 'SubPanelDetailViewLink'," 

I tried using displayParams to shorten the field but (to no surpise give it is a widget), this did nothing

'displayParams' => array (
    'maxlength' => 8,
),

Does anyone know how to shorten/truncate the number of characters being displayed in a column entry in a subpanel (without actually changing the field value)?

  • for fields that are using a widget like “SubPanelDetailViewLink”
  • for “normal” fields like text fields, …

In theory, process_record hook should be the way to go, even for subpanels:

@pgr

Thank you for your quick reply.

I am having no luck with using a logic hook to shorten the number of characters displayed in each record in a subpanel.

I have tried a process_record logic hook in the target module - my custom module AYU_Funds.
I have tried a process_record logic hook in the module displaying the subpanel - Accounts.

No luck.

The SuiteCRM Developer Guide says the process_record logic hook fires:

Fired when a record is processed ready to be displayed in list views or dashlets.

so it does not look like it is intended for use to affect subpanels data … unless the “listing” of records in a subpanel qualifies as a List View.

Part of the challenge is the field name to use so maybe I am just not using the correct field name in my logic hook code. The field I am trying to shorten is the name field from the target module. But when I use $bean->name in the logic hook code in the Accounts module, it shortens the name of the Account in the Account’s List View (no surprise there).

I have tried using the link name and the parent name instead but no change.

Any ideas?

I know that the subpanels utilize some variation of list view code, but I don’t know the exact borders between those classes.

But it shouldn’t be too hard to find out. If you set a breakpoint inside your hook, does it fire when the subpanel is displayed? And then you can inspect the data structures available there to see where your field is.

@Ramblin

The logichook ‘process_record’ works for listview and dashlets only. You can look at documentation (Logic Hooks :: SuiteCRM Documentation). I think that you can use the logichook ‘after_retrieve’,

@pgr @p.konetskiy

Thank you both for your quick replies.

It is now working.

I had been putting the logic hook call in the wrong place (wrong module) and using the wrong “name” (using the link name).

I also had a condition in the existing logic hook code that checked if the code was being called by the custom modue (AYU_Funds) and if not, ignore the code.

Turns out all of the above were contributing to it not working, which, once fixed, it is working fine.

Once you both said it should be working, I starting debugging and here we are.

So, although this is a rather unique scenario, if anyone else comes across a need to shorten the number of characters being displayed in a subpanel list, it is very simple.

In my case, I had a subpanel for my custom module (AYU_Funds) in Accounts (and Contacts and Events but will only show for Accounts; it works the same for the others)

If you want to affect the display of the field in the AYU_Funds subpanel in Accounts, you make the changes in the AYU_Funds logic hook, NOT in the Accounts logic hook. That way, when you call the data for the subpanel in Accounts, it fetches the data - AND the settings - from the AYU_Funds module.

So, to shorten the number of characters displayed for a variable (in my case “name” of AYU_Funds) in BOTH the list view for AYU_Funds List View AND in any subpanel calling from AYU_Funds (which displays the variable (“name”))

The hook goes into:
custom/Extension/modules/AYU_Funds/EXT/LogicHooks/aNameYouChoose.php

<?php
$hook_version = 1;
$hook_array = Array();
 // position, file, function
$hook_array['process_record'] = Array();
$hook_array['process_record'][] = Array(
    25,
    'Shorten the length of the Name field for display',
    'custom/modules/AYU_Funds/truncateNameDisplay.php',
    'truncateNameDisplay',
    'shortenNameFieldLength',
);

and in custom/modules/AYU_Funds/truncateNameDisplay.php

<?php

if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}

class truncateNameDisplay {
    function shortenNameFieldLength( $fundBean , $event , $arguments ) {
        $fundBean->name = substr( $fundBean->name , 0 , 8 );
    }
}

Thank again for pointing me in the right direction