Working with timezones in BPM E-mail templates

Hi, 

for a customer we have a BPM workflow that uses a e-mail template which contains a date/time field from a certain record. The only purpose of the BPM is to send out a notification to a specified contact, in the record of the custom module just created, The problem I'm facing is that the date/time that is mentioned in the field is not correct. It is shown as the UTC version of the date/time. I would have expected to be converted to the timezone from the person who is sending out the mail (or the from the person that created the record in the first place). 

According to Sugar that is a known issue and a enhancement request is created for it. Is there someone in the club who faces the same issue and has already solved it? 

Parents
  • Hi , I had to customize BPM once and it was fairly straightforward.

    I did a quick check in the code and the issue that you mention comes from modules/pmse_Inbox/engine/PMSEHandlers/PMSEBeanHandler.php, function mergingTemplate

    Here is the code that substitutes the UTC date firectly from DB:

    // Handle date/datetime, and boolean, field types
    // to maintain proper UTC values
    if (in_array($def['type'], ['datetime', 'datetimecombo']) && !empty($newBean->fetched_row[$fieldName])) {
    $value = $newBean->fetched_row[$fieldName];
    }

    So all we have to do is to customize the PMSEBeanHandler, and thankfully the mergingTemplate function is public:

    The PMSE code indeed allows custom classes, so once we create custom/modules/pmse_Inbox/engine/PMSEHandlers/CustomPMSEBeanHandler.php and extend the mergingTemplate, we probably have two options:

    1. Copy the entire mergingTemplate function, modify the part where it uses fetched_row

    2. Another option is to just call parent::mergingTemplate and detect if there are dates, and apply an override in the returned value.

    Hope it helps!

Reply
  • Hi , I had to customize BPM once and it was fairly straightforward.

    I did a quick check in the code and the issue that you mention comes from modules/pmse_Inbox/engine/PMSEHandlers/PMSEBeanHandler.php, function mergingTemplate

    Here is the code that substitutes the UTC date firectly from DB:

    // Handle date/datetime, and boolean, field types
    // to maintain proper UTC values
    if (in_array($def['type'], ['datetime', 'datetimecombo']) && !empty($newBean->fetched_row[$fieldName])) {
    $value = $newBean->fetched_row[$fieldName];
    }

    So all we have to do is to customize the PMSEBeanHandler, and thankfully the mergingTemplate function is public:

    The PMSE code indeed allows custom classes, so once we create custom/modules/pmse_Inbox/engine/PMSEHandlers/CustomPMSEBeanHandler.php and extend the mergingTemplate, we probably have two options:

    1. Copy the entire mergingTemplate function, modify the part where it uses fetched_row

    2. Another option is to just call parent::mergingTemplate and detect if there are dates, and apply an override in the returned value.

    Hope it helps!

Children
  • Thanks for the help. I'm currently trying to implement the custom PMSE Handler but I cant get it to work. I created a custom class (see below) in custom/modules/pmse_Inbox/engine/PMSEHandlers/CustomPMSEBeanHandler.php. After a QRR and when the BPM flows are running I do get an 500 error that tells me that the class can not be found... Any idea why that is happening? 

    <?php
    
    namespace custom\modules\pmse_Inbox\engine\PMSEHandlers;
    
    class CustomPMSEBeanHandler extends \PMSEBeanHandler
    {
        public function __construct()
        {
            parent::__construct();
            $GLOBALS['log']->fatal('Custom PMSE Bean handler called');
        }
    
    
        public function mergingTemplate($bean, $template, $components, $evaluate){
            $GLOBALS['log']->fatal(sprintf("%s -> %s called ",__CLASS__,__FUNCTION__));
            parent::mergingTemplate($bean,$template,$components,$evaluate);
        }
    
    }