📣 We're Hiring!

Comment Log feature for SuiteCRM

Hello,

I am looking to have an automatic timestamp appear whenever someone updates a text area in the contacts module. I found this is a feature within SugarCRM (https://sugarclub.sugarcrm.com/explore/enterprise-professional/f/enterprise-professional-questions/2748/timestamp-a-text-field-or-text-area-with-date-time-and-user) and I was wondering if it is possible to get this feature in SuiteCRM.

If the comment log feature can’t be used, does anyone have any suggestions on how to get a timestamp to appear every time someone adds a new piece of text to a text area within a specific module?

Check out the “threaded updates” feature in the Cases module, is that similar to what you need?

Hi,
have you considered using the audit feature? It would keep track of each change and it would display the old value, the new value, who did the change and the respective timestamp in a popup-window (viewable per record). It’s an inbuilt feature and just needs to be activated.

otherwise, you do that with a workflow:

  • on-save, with repeated runs
  • action: save the current field value in a parameter. Prepend your timestamp like this:

result:

Thank you for the quick reply!

I like your idea of using a workflow to do this. Could you possibly give me a little more insight on what I would need to put for my condition and the specific action I would need to perform?

That’s pretty close to what I am trying to accomplish, however the workflow @diligent suggested is exactly what I am looking for. Thank you for the fast reply!

Hey,
if needed, I can upload the complete workflow as a screenshot. I will also switch the language to make it more readable to you :slight_smile:

That would be super helpful, I appreciate it! :smile:

I added a condition in the meantime, so the workflow is only triggered when someone is actually modifying the field.

Btw, you could make this field “read only” too (as your users could currently delete/modify the whole history):

  • create a new field (temp_text).
    • show temp_text only in EditView
    • a second field should be added to the DetailView (complete_text), but not to the EditView
  • on save
    • prepend the temp_text field to the second field with the timestamp (nearly the same formula as above).
  • and empty the temp_text field.

Not tested, but this way, your users can add new comments in the empty field, and on-save, the temporary field is merged into the complete history (a non-modifiable field).

E: would work in general, but I wasn’t able to insert a linebreak/new line in my formula, otherwise I would have shared that approach too.

Thank you so much for providing me with the workflow screenshot. I followed your design and the timestamp applied great. I am interested in this statement as well.

Btw, you could make this field “read only” too (as your users could currently delete/modify the whole history):

  • create a new field (temp_text).
    • show temp_text only in EditView
    • a second field should be added to the DetailView (complete_text), but not to the EditView
  • on save
    • prepend the temp_text field to the second field with the timestamp (nearly the same formula as above).
  • and empty the temp_text field.

I would like to try this so I could prepend a new note to the top of the detailview of the description box. I have already declared the detail view ‘Contact Notes’ to be ‘read only’ and have my temp_text field set to be cleared on save and hidden from the detail view.

The text I input into the temp_text field transfers over to the ‘Contact Notes’ field just fine, but when I go to add a new line, temp_text writes over my first note that I had saved. Do you have any suggestions on how to get the ‘Contact Notes’ field to keep older notes from being deleted by the temp_text field?

Screenshot of my workflow:

Thanks!

You were close:

this solution works, but as you can see here:

chrome_0HSDcpNW2H

there is no new line for the newly added comment, its just prepended. I’ve tried some ideas, but wasn’t able to accomplish more (maybe someone here as additional ideas).

If you consider code-changes too btw, it would be very easy to do this feature as a logic hook.

Thank you for all your help! Having a logic hook create the new line sounds like a good idea. I’m new to developing so I haven’t really dove into Logic Hooks but I’m going to give it a shot. Would it be easier to have the Logic Hook create the timestamp too or should I leave the workflow as is and just make the hook create a new line?

Hi,
we can also assist you in writing that hook if you encounter problems, just give it a try.

But to answer your question: no, deactivate your workflow and do everything from within the hook, its the more reliable solution (and you have full freedom in what you do!).

Hi @diligent,

I am very new to Logic Hooks and don’t quite know how to get this done. I have added these lines to my logic_hooks.php file in /custom/modules/contacts:

$hook_version = 1; 
$hook_array = Array(); 
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'Store values', 'custom/modules/Contacts/My_Logic_Hooks.php', 'My_Logic_Hooks', 'AddNewLine' );

Then I created a new file called My_Logic_Hooks.php in the same directory with the following code:

<?php 
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class My_Logic_Hooks {
  function AddNewLine($bean, $event, $arguments) {
  $bean->description = $bean->description . "\r"; // both of these worked
  }
}

I was following a guide here: https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/397/calculate-field-with-line-breaks
but couldn’t get much farther than what I have.

Any help would be appreciated as always :slight_smile:

Hi,
I’ve updated your example - can you see it work already (are you seeing some results after saving)?

Hi,
I changed my code and entered in the name of my new comment field. After running a quick repair and rebuild I am not seeing any results show up. Do I need to enable Logic Hooks anywhere in the code or settings?

mh, nothing comes to mind…I’ll test your code tomorrow, can you post all code changes you did with the relative paths?

The only code changes I have done have been creating this Logic Hook in C:\SuiteCRM\custom\modules\Contacts

logic_hooks.php:

<?php
// Do not store anything in this file that is not part of the array or the hook version.  This file will	
// be automatically rebuilt in the future. 
 $hook_version = 1; 
$hook_array = Array(); 
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'Store values', 'custom/modules/Contacts/My_Logic_Hooks.php', 'My_Logic_Hooks', 'AddNewLine' );
// position, file, function 
$hook_array['before_save'] = Array(); 
$hook_array['before_save'][] = Array(6, 'Contacts push feed', 'modules/Contacts/SugarFeeds/ContactFeed.php','ContactFeed', 'pushFeed'); 
$hook_array['before_save'][] = Array(77, 'updateGeocodeInfo', 'modules/Contacts/ContactsJjwg_MapsLogicHook.php','ContactsJjwg_MapsLogicHook', 'updateGeocodeInfo'); 
$hook_array['after_save'] = Array(); 
$hook_array['after_save'][] = Array(7, 'Update Portal', 'modules/Contacts/updatePortal.php','updatePortal', 'updateUser'); 
$hook_array['after_save'][] = Array(77, 'updateRelatedMeetingsGeocodeInfo', 'modules/Contacts/ContactsJjwg_MapsLogicHook.php','ContactsJjwg_MapsLogicHook', 'updateRelatedMeetingsGeocodeInfo'); 
?>

and My_Logic_Hooks.php:

<?php 
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class My_Logic_Hooks {
  function AddNewLine($bean, $event, $arguments) {
 $bean->description = date("Y-m-d H:i:s") . ': ' . $bean->temp_text_c  . "\r" . $bean->description;
  }
}

The only other code change I have done was adjusting the editviewdefs.php and detailviewdefs.php files in every module to accommodate for a 4-column layout instead of 2-column.

Hi,
I shortly copied everything and it seems to work just fine:

First, modify custom/modules/Contacts/logic_hooks.php:

$hook_array['before_save'][] = Array(99, 'Store values', 'custom/modules/Contacts/My_Logic_Hooks.php', 'My_Logic_Hooks', 'AddNewLine' );

I’ve added this row as the last “Before_save” item.

Then I’ve added
custom/modules/Contacts/My_Logic_Hooks.php like this:

<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class My_Logic_Hooks {
    function AddNewLine($bean, $event, $arguments) {
        $bean->complete_history_c = date("Y-m-d H:i:s") . ': ' . $bean->temp_history_c  . "\r" . $bean->complete_history_c;
        $bean->temp_history_c = '';
    }
}

Result:

If it still doesnt work, please have a look in your logfiles and validate first if your newly created file (My_Logic_Hooks.php) is owned by the correct user (if you’re using unix).

E: it just came to my mind that this hook would add a new line on each save. Therefore, I would add a validation first, like:

function AddNewLine($bean, $event, $arguments) {
        if($bean->temp_history_c !== ''){
           $bean->complete_history_c = date("Y-m-d H:i:s") . ': ' . $bean->temp_history_c  . "\r" . $bean->complete_history_c;
           $bean->temp_history_c = '';
        }
    }

Thank you so much! The logic hooks works as intended.

I ran into an issue where my text area on detail view does not auto resize.

I’ll put text in like this:

And when I save the hook works and the timestamp is appended:

But when I go to add a second note the text area doesn’t grow:

I can tell the hook is working because if I turn on inline edit I can see the new line:

Is there a way to control the height of the text area on detail view?

Update: After restarting my SuiteCRM server everything is working as intended. Text no longer displays in a single line. Thank you.