How can I store todays date in a date field ?

Hi there, 

After browsing and reading for quite some time in the available online info from Sugar, I coudln't find what I was looking for...

I was asked to store the date when a Lead goes in the an 'end' state (converted, recycled, dead) in a separate date field. Limitation : I only have Studio and BPM as tools available. "Last activity" and "Last modified" out of the box fields don't fit the needs.
Is that possible to do via either way via Studio or BPM ?

Thanks

Hugo

Parents
  • Hello ,

    If you want to add today's date in a different field when the state (converted, recycled, dead). You can do it by code by creating API or by hooks.

    In my sense Hooks will be better for doing that
    public/custom/modules/<moduleName>/<Your Hook>.php

    <?php
    require_once 'include/SugarQuery/SugarQuery.php';
    require_once 'include/api/SugarApiException.php';
    class CustomHooksName
    {
        public function afterSave($bean, $event, $arguments)
        {
            $this->updateDateAfterConvert($bean, $event, $arguments);
        }
        
        private function updateDateAfterConvert($bean, $event, $arguments)
        {
            if ($bean->status == 'Recycled' || $bean->status == 'Converted' || $bean->status == 'Dead') {
                // get Utc time
                date_default_timezone_set('UTC');
                $today = date("Y-m-d H:i:s");
                $bean->$status_updated_date_c = $today;
                $bean->save();
            }
        }
    }

    To ensure it is working you have to add another file to 

    /srv/users/<userName>/apps/<InstanceName>/public/custom/Extension/modules/<ModuleName>/Ext/LogicHooks

    in this folder Add a file after_save.php

    <?php
    
    $hook_array['after_save'][] = array(
      1,
      'After Save Functionality',
      'custom/modules/<ModuleName>/CustomHooksName.php',
      'CustomHooksName',
      'afterSave'
    );


    After adding those files do Quick Repair and Rebuild.


    After doing you can try whether it is working or not.

    Thank you

Reply
  • Hello ,

    If you want to add today's date in a different field when the state (converted, recycled, dead). You can do it by code by creating API or by hooks.

    In my sense Hooks will be better for doing that
    public/custom/modules/<moduleName>/<Your Hook>.php

    <?php
    require_once 'include/SugarQuery/SugarQuery.php';
    require_once 'include/api/SugarApiException.php';
    class CustomHooksName
    {
        public function afterSave($bean, $event, $arguments)
        {
            $this->updateDateAfterConvert($bean, $event, $arguments);
        }
        
        private function updateDateAfterConvert($bean, $event, $arguments)
        {
            if ($bean->status == 'Recycled' || $bean->status == 'Converted' || $bean->status == 'Dead') {
                // get Utc time
                date_default_timezone_set('UTC');
                $today = date("Y-m-d H:i:s");
                $bean->$status_updated_date_c = $today;
                $bean->save();
            }
        }
    }

    To ensure it is working you have to add another file to 

    /srv/users/<userName>/apps/<InstanceName>/public/custom/Extension/modules/<ModuleName>/Ext/LogicHooks

    in this folder Add a file after_save.php

    <?php
    
    $hook_array['after_save'][] = array(
      1,
      'After Save Functionality',
      'custom/modules/<ModuleName>/CustomHooksName.php',
      'CustomHooksName',
      'afterSave'
    );


    After adding those files do Quick Repair and Rebuild.


    After doing you can try whether it is working or not.

    Thank you

Children
No Data