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

  • 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

  • Hi  ,

    SugarBPM is perfectly suited to meet this use case. The foundation of your process definition would have the following:

    • A start event on all updated records with a field condition of the status changing to the desired trigger values:
    • An action event set to 'Change Fields' and updating the custom date field to a value of 'Run Time' so it records the current date:
    • An end event to conclude the process

    Once you connect all those elements on the canvas, it should look like this:

    Let me know if you have any questions!

    Chris

  • Hi Chris,

    I've entered your suggestions as displayed/described. Restarted my webbrowser (don't know if that was necessary). Closing a lead  however does not fill in todays date in my "Date Closed" field.

    Is this something that should be visible immediately ? Is there something I overlooked ? (your solution seems the simplicity itself, so... ;-) ) 

    Thanks

    Hugo

  • Hi  ,

    When creating a new process definition, it is disabled by default. Did you check to ensure the status is enabled? If it is enabled, do you see a new entry get created in the Admin > Process Management section? If you don't see a corresponding entry in Process Management, then the process start event is not triggering based on the conditions you set.

    Let me know your findings and we can dig deeper if it still isn't working.

    Chris

  • Hi Chris,

    Process was indeed switched to 'enabled', but Process Management didn't show it after I tried to close about 3 leads....
    Removing the condition on the Start event completely however, did triggered the process and copied the date into the Date closed field...I added 1 status back in the condition field, still worked, added OR and a second status, still worked, added OR and the 3rd status : now it keeps on working well. Weird things, computers...
    So thanks a lot for your hint : we made another user very happy. ;-)

    Bye now

    Hugo

  • Hi  ,

    I've also encountered similar "ghosts" when working with SugarBPM where recreating the element worked. It's a strange issue, and by the time you fix it, you've lost the ability for Sugar Support to diagnose what happened since it now works. I'm glad to hear it's working for you!

    Chris