Results 1 to 8 of 8

Thread: Logic Hook - before save problem

  1. #1
    kinshibuya's Avatar
    kinshibuya is offline A Sugar Hero
    Join Date
    Jul 2008
    Location
    brasil
    Posts
    521

    Default Logic Hook - before save problem

    Hi. I'm using 5.2 and i'm having a big problem.
    I added a custom field 'datetime' in
    custom/Extension/modules/Cases/Ext/Vardefs/additionaldetailsfromSup_suporte.php
    Code:
    $dictionary["Case"]["fields"]["data_vencimento_c"] = array (
          'required' => '0',
          'source' => 'custom_fields',
          'name' => 'data_vencimento_c',
          'vname' => 'LBL_DATA_VENCIMENTO_C',
          'type' => 'datetime',
          'massupdate' => '0',
          'default' => NULL,
          'comments' => '',
          'help' => '',
          'importable' => 'true',
          'duplicate_merge' => 'disabled',
          'duplicate_merge_dom_value' => '0',
          'audited' => 1,
          'reportable' => 0,
          'id' => 'Casesdata_vencimento_c',
          'custom_module' => 'Cases',
    );
    When i do repair/rebuild the field doesn't go to Casevardefs.php
    I also have a Logic hook to update this field on the Database:
    /custom/Cases/logic_hooks.php
    Code:
    <?php
    // Do not store anything in this file that is not part of the array or the hook version.  This file will	
    // be automatically rebuilt in the future. 
     $hook_version = 2; 
    $hook_array = Array(); 
    // position, file, function 
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(2,'dtvenc', 'modules/Cases/CaseLogicHook.php','CaseLogicHook', 'dtvenc'); 
    $hook_array['before_save'][] = Array(5, 'Cases push feed', 'modules/Cases/SugarFeeds/CaseFeed.php','CaseFeed', 'pushFeed'); 
    
    ?>
    /modules/Cases/CaseLogicHook.php
    Code:
    <?php
    
     if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 
    
    class CaseLogicHook { 
        function dtvenc(&$focus, $event, $arguments) { 
    
    	global $db; 
    $query = "UPDATE cases_cstm cas SET cas.data_vencimento_c=(SELECT ADDTIME(SUBTIME(c.date_entered,'03:00:00'), (CASE WHEN c.type='Software' THEN (CASE WHEN c.priority='P0' THEN s.slacriressw ELSE (CASE WHEN c.priority='P1' THEN s.slaaltressw ELSE (CASE WHEN c.priority='P2' THEN s.slamedressw ELSE s.slabairessw END) END) END) ELSE (CASE WHEN c.priority='P0' THEN s.slacrireshw ELSE (CASE WHEN c.priority='P1' THEN s.slaaltreshw ELSE (CASE WHEN c.priority='P2' THEN s.slamedreshw ELSE s.slabaireshw END) END) END) END)) " .
    "from sup_contratosuporte s, sup_contratuporte_cases_c cstm, cases c where s.id=cstm.sup_contra8d4esuporte_ida and c.id=cstm.sup_contra20a5escases_idb and c.deleted=0 and cstm.deleted=0 and s.deleted=0 and c.id=  '" . $focus->id . "') " . 
    " where cas.id_c= '" . $focus->id . "'";
    $result = $db->query($query, true, 'Error ao atualizar data de vencimento');
    
    }
    
    }
    
    
    ?>
    The logic hook work just fine.
    When i manualy add the field to Casevardefs.php the logic hook stop working!
    Can anyone help my on this one?
    Priscila Kin Yamamoto Joranhezon
    Phone: +55 61 32010000
    priscila.joranhezon@nct.com.br
    NCT Informática Ltda

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Logic Hook - before save problem

    Hi Priscila

    I believe I already answered a question like that before.
    This is a custom field, so you would be able to create its through Studio.
    Why to create its through extended vardefs?
    I'm not sure but I think you can not set/update custom fields through extended vardefs.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    kinshibuya's Avatar
    kinshibuya is offline A Sugar Hero
    Join Date
    Jul 2008
    Location
    brasil
    Posts
    521

    Default Re: Logic Hook - before save problem

    Actually i created it by studio but since my cahce is not updating i couldn't change it to 'datetime'.
    So i decided to create it by extended vardefs.
    Is there anything i could do to repair this cache problem?
    Priscila Kin Yamamoto Joranhezon
    Phone: +55 61 32010000
    priscila.joranhezon@nct.com.br
    NCT Informática Ltda

  4. #4
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Logic Hook - before save problem

    You can update the related record on fields_meta_data and alter the table cases_cstm to accomplish the changes.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  5. #5
    kinshibuya's Avatar
    kinshibuya is offline A Sugar Hero
    Join Date
    Jul 2008
    Location
    brasil
    Posts
    521

    Default Re: Logic Hook - before save problem

    Yes! thank you i added the field throw Studio and set the type to datetime, but it's not working.
    I checked the sugarcrm.log and i found this:

    Code:
    Tue Jul 21 10:35:05 2009 [16643][ab7b4a18-87a0-2f07-0fb4-4868c775ad0f][INFO] Query:UPDATE cases_cstm cas SET cas.data_vencimento_c=(SELECT ADDTIME(SUBTIME(c.date_entered,'03:00:00'), (CASE WHEN c.type='Software' THEN (CASE WHEN c.priority='P0' THEN s.slacriressw ELSE (CASE WHEN c.priority='P1' THEN s.slaaltressw ELSE (CASE WHEN c.priority='P2' THEN s.slamedressw ELSE s.slabairessw END) END) END) ELSE (CASE WHEN c.priority='P0' THEN s.slacrireshw ELSE (CASE WHEN c.priority='P1' THEN s.slaaltreshw ELSE (CASE WHEN c.priority='P2' THEN s.slamedreshw ELSE s.slabaireshw END) END) END) END)) from sup_contratosuporte s, sup_contratuporte_cases_c cstm, cases c where s.id=cstm.sup_contra8d4esuporte_ida and c.id=cstm.sup_contra20a5escases_idb and c.deleted=0 and cstm.deleted=0 and s.deleted=0 and c.id=  '54a24dad-9bc1-db62-8660-4a64bf67b0e5')  where cas.id_c= '54a24dad-9bc1-db62-8660-4a64bf67b0e5'
    Tue Jul 21 10:35:05 2009 [16643][ab7b4a18-87a0-2f07-0fb4-4868c775ad0f][INFO] Query Execution Time:0.00088405609130859
    Tue Jul 21 10:35:05 2009 [16643][ab7b4a18-87a0-2f07-0fb4-4868c775ad0f][INFO] Query:UPDATE cases_cstm SET  sla_c='imediato' ,competencia_c='Cliente' ,data_vencimento_c='1969-12-31 00:00:00' WHERE id_c='54a24dad-9bc1-db62-8660-4a64bf67b0e5'
    Tue Jul 21 10:35:05 2009 [16643][ab7b4a18-87a0-2f07-0fb4-4868c775ad0f][INFO] Query Execution Time:0.00033783912658691
    aparently sugar is updating my field data_vencimento_c with some strange date. it probably is default value, i already set it to null, what else can i do?
    Last edited by kinshibuya; 2009-07-21 at 02:44 PM. Reason: added more lines
    Priscila Kin Yamamoto Joranhezon
    Phone: +55 61 32010000
    priscila.joranhezon@nct.com.br
    NCT Informática Ltda

  6. #6
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Logic Hook - before save problem

    Did you run quick repair and rebuild?

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  7. #7
    kinshibuya's Avatar
    kinshibuya is offline A Sugar Hero
    Join Date
    Jul 2008
    Location
    brasil
    Posts
    521

    Default Re: Logic Hook - before save problem

    Yep!
    No changes. Is there a way to desable this UPDATE in the custom fields on this module? it wouldn't make a diference.
    Priscila Kin Yamamoto Joranhezon
    Phone: +55 61 32010000
    priscila.joranhezon@nct.com.br
    NCT Informática Ltda

  8. #8
    kinshibuya's Avatar
    kinshibuya is offline A Sugar Hero
    Join Date
    Jul 2008
    Location
    brasil
    Posts
    521

    Default Re: Logic Hook - before save problem

    Hi André!!
    Thanks for all the replys!
    It's working now!
    I changed to a after_save logic hook!

    Code:
    <?php
    // Do not store anything in this file that is not part of the array or the hook version.  This file will	
    // be automatically rebuilt in the future. 
     $hook_version = 2; 
    $hook_array = Array(); 
    // position, file, function 
    $hook_array['before_save'] = Array();
    $hook_array['after_save'][] = Array(2,'dtvenc', 'modules/Cases/CaseLogicHook.php','CaseLogicHook', 'dtvenc'); 
    $hook_array['before_save'][] = Array(5, 'Cases push feed', 'modules/Cases/SugarFeeds/CaseFeed.php','CaseFeed', 'pushFeed'); 
    
    ?>
    Priscila Kin Yamamoto Joranhezon
    Phone: +55 61 32010000
    priscila.joranhezon@nct.com.br
    NCT Informática Ltda

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Cancel save in logic hook
    By eggsurplus in forum Developer Help
    Replies: 4
    Last Post: 2012-02-08, 09:37 AM
  2. Prevent sugar save in logic hook
    By jjshoe in forum Developer Help
    Replies: 1
    Last Post: 2009-03-02, 09:40 PM
  3. save & skip logic hook
    By mikesolomon in forum Developer Help
    Replies: 2
    Last Post: 2008-11-05, 12:59 PM
  4. Replies: 3
    Last Post: 2008-07-20, 06:09 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
  •