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? 

  • 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!

  • IT seems that the same issue is now arrising on the old workflow module. The customer switched to the old workflows because in 10.1 it seemed that this issue was not on there. Does anyone know what we can do to fix it in the old workflow? 

  • 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);
        }
    
    }

  • Yeah the old workflow has been set to maintenance mode for quite some time indeed.

  • <?php
    
    //namespace custom\modules\pmse_Inbox\engine\PMSEHandlers;
    
    require_once 'modules/pmse_Inbox/engine/PMSEHandlers/PMSEBeanHandler.php';
    
    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);
        }
    
    }

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

  • Many thanks. It works now. I'm still a bit confused to why when using namespaces it does not work? Could you explain that to me (and others who are reading this)

  • If you want to use a namespace, try to use it from ProcessManager:

    <?php
    
    use Sugarcrm\Sugarcrm\ProcessManager;
    
    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);
        }
    
    }

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH