Results 1 to 3 of 3

Thread: How can I override the date_entered value using the edit view/action (logic hook)?

  1. #1
    jjwdesign's Avatar
    jjwdesign is offline Sugar Community Member
    Join Date
    Dec 2006
    Location
    Orlando, FL
    Posts
    503

    Default How can I override the date_entered value using the edit view/action (logic hook)?

    Our sale manager gave me a task today that sounded reasonable, until I started to try to figure it out. Here's the background story. We have a bunch of leads that come in during the week from a mall booth display. We'd like to record "exactly" what days the leads came in on (time is not that important). Unfortunately, sales people often bring in the leads on the next day or on the following Monday, to be imported into the system. Our sale administrator usually handles the imports and conversions so our sales team can focus on the opportunities.

    The problem we are having is that the date_entered and the day the lead was generated is not always the same. We've got a ton of leads with the wrong date_entered values.

    So, how can I allow our Sales Administrator to update the date entered.
    - Without SQL updates
    - Without importing (as it's already imported)

    I thought about setting up an override field in the Lead and then using a logic hook to overwrite the data_entered, but it doesn't seem to be working. Maybe there's a better approach

    PHP Code:
    function updateDateEntered(&$bean$event$arguments) {
            
    // Update the date_entered field based on entered_override_c field.
            
    if (!empty($bean->entered_override_c)) {
                    
    $bean->date_entered $bean->entered_override_c;
                    
    $bean->entered_override '';
                    
    $bean->save(FALSE);
            } 
    // if isset
    // end of updateDateEntered 


    Thanks,
    Jeff Walters
    Last edited by jjwdesign; 2010-02-26 at 07:53 PM.
    SugarForge Projects:
    JJWDesign Google Maps
    JJWDesign Tools and Reports

    Follow my blog postings at JJW Design.

  2. #2
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: How can I override the date_entered value using the edit view/action (logic hook)

    date_entered cannot be set in a hook but you can set it yourself, e.g. for cases you could set it like that:

    PHP Code:
             $db = & PearDatabase::getInstance();
             
    $query "UPDATE cases set date_entered ='".$bean->entered_override_c."' WHERE id='$bean->id';";
             
    $result $db->query($querytrue,"Error setting date_enterd: "); 
    Harald Kuske
    Pre-Sales Engineer Central Europe

    SUGARCRM Deutschland GmbH
    Erika-Mann-Str. 53, 80636 Munich, Germany
    Email: hkuske@sugarcrm.com
    Home: http://www.sugarcrm.com


  3. #3
    jjwdesign's Avatar
    jjwdesign is offline Sugar Community Member
    Join Date
    Dec 2006
    Location
    Orlando, FL
    Posts
    503

    Default Re: How can I override the date_entered value using the edit view/action (logic hook)

    Thanks for the reply Kuske. Well, actually... I think I made it work. I'm using v5.2 CE. I was researching the forum posts and ran across a couple of interesting post. One showed how to set the date entered and date modified as importable.

    Extension - Custom Vardef
    /custom/Extension/modules/Leads/Ext/Vardefs/update_entered_vardefs.php
    PHP Code:
    <?php 
    $dictionary
    ['Lead']['fields']['date_entered']['importable'] = true
    $dictionary['Lead']['fields']['date_modified']['importable'] = true
    ?>
    Then, using a "before_save" logic hook you can set the value. The second post I found. pointed out the user date format perferences. It requires some date/time traslations, but it can be done. See code below.
    PHP Code:
        function updateDateEntered(&$bean$event$arguments) {
        global 
    $current_user$sugar_config;
        
    $udf $current_user->getPreference('datef');
        if (
    $udf == "") {
            
    $udf $sugar_config['default_date_format'];
        }
       
    // Update the date_entered field based on entered_override_c field.
       
    if (!empty($bean->entered_override_c)) {
                
    $bean->date_entered gmdate("Y-m-d"strtotime($bean->entered_override_c))." 16:11:11";
                
    $bean->entered_override_c '';
            } 
    // if not empty
        
    // end of updateDateEntered 
    I'm not sure if the custom vardef is needed, but it will help with my imports in the future. I'm also not sure if this creates any serious security issues. Even if it does, it's only leads. This way will also allow you to audit the fields to see who makes changes.

    Cheers,
    Jeff Walters
    SugarForge Projects:
    JJWDesign Google Maps
    JJWDesign Tools and Reports

    Follow my blog postings at JJW Design.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Cancel an edit from a logic hook
    By pauloalexandrino in forum Developer Help
    Replies: 21
    Last Post: 2012-04-21, 03:05 AM
  2. Logic Hook Depends Create or Edit
    By Niggy in forum Developer Help
    Replies: 5
    Last Post: 2009-08-07, 08:23 AM
  3. Changing the return action using a logic hook?
    By jjwdesign in forum Developer Help
    Replies: 3
    Last Post: 2009-02-26, 04:10 PM
  4. Override view.edit.php to make fields readonly
    By eggsurplus in forum Developer Help
    Replies: 7
    Last Post: 2008-10-09, 03:44 PM
  5. Showing name of related item in list view - logic hook?
    By dogfuel in forum Developer Help
    Replies: 2
    Last Post: 2008-01-04, 11:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •