How to create logic hook in SuiteCRM Leads to calculate and display Days Since Last Activity for a given record.

This would be displayed in a new field Days Since Last Activity and based on Today minus Date Modified.

you can achieve this with logic hooks if you don’t have a clue what is that let me hint you with some documentation

best regards

Hi Mike,

I do know what logic hooks are. I was hoping someone with experience creating them could offer some sample code.

following this documentation for logic hooks
and this for php

you can have something like this


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

    class logic_hooks_class
        function after_retrieve_method($bean, $event, $arguments)
                $date_modified = $bean->date_modified;
                $datetime1 = new DateTime();
                $datetime2 = new DateTime($date_modified);
                $interval = $datetime1->diff($datetime2);
                $elapsed = $interval->format('%a');
                $bean->days_since_last_activity_c = $elapsed;


the field days_since_last_activity_c I created it in studio and added to the detail view, because my hook gets called when the entry is being retrieved from the database, but remember that date_modified only gets populated if you modify something in that particular entry, not when adding, removing, etc relations i.e. calls, meetings, etc. for that you will have to make something more elaborated than that, or maybe i’m wrong.

best regards

thank you!