Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Problem counting in logic hook

  1. #1
    dekleinemedia is offline A Prolific Poster
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    241

    Question Problem counting in logic hook

    Hi,

    I have the following issue;

    I have created a logic_hook for ProjectTask. It increases every time a new projecttask is created.
    This works fine, untill i create projecttask '11'.
    The counting stocks when its creating a new task above '10'
    Taskname '11' will get the same tasknumber '10' see screenshot
    Also is my sorting not working propaply see screenshot

    In my attachment you will find the logic_hook.
    Can someone please tell me what is wrong? I appreciate

    thankss
    Attached Images Attached Images  
    Attached Files Attached Files
    Kind regards,

    De Kleine Media


    SugarCRM CE v.5.2.0h
    Windows platform
    MySQL v.5.1
    phpMyAdmin - 2.11.2.2
    Apache Server v.2.0

  2. #2
    ros.vol is offline Sugar Community Member
    Join Date
    Dec 2008
    Location
    Eastern Europe / Ukraine / Chernivtsi
    Posts
    114

    Smile Re: Problem counting in logic hook

    Hello,

    AS i can see from the sceenshot - sorting is going under varchar type.

    You should convert them into the integer type value.

    Cheers,
    Rostyslav Volonchuk

    SugarCRM development and customizations

  3. #3
    dekleinemedia is offline A Prolific Poster
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    241

    Default Re: Problem counting in logic hook

    Quote Originally Posted by ros.vol View Post
    Hello,

    AS i can see from the sceenshot - sorting is going under varchar type.

    You should convert them into the integer type value.

    Cheers,
    Yes, you are correct. It is indead sorting under varchar type. Can you tell me how to convert this into a integer type value?

    Many thanks!
    Kind regards,

    De Kleine Media


    SugarCRM CE v.5.2.0h
    Windows platform
    MySQL v.5.1
    phpMyAdmin - 2.11.2.2
    Apache Server v.2.0

  4. #4
    ros.vol is offline Sugar Community Member
    Join Date
    Dec 2008
    Location
    Eastern Europe / Ukraine / Chernivtsi
    Posts
    114

    Smile Re: Problem counting in logic hook

    How did you define Task# in vardefs?
    Rostyslav Volonchuk

    SugarCRM development and customizations

  5. #5
    dekleinemedia is offline A Prolific Poster
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    241

    Default Re: Problem counting in logic hook

    Quote Originally Posted by ros.vol View Post
    How did you define Task# in vardefs?
    Hi,

    These are my fielddefs of task_number

    'task_number' => array (
    'required' => '1',
    'name' => 'task_number',
    'vname' => 'LBL_TASK_NUMBER',
    'type' => 'varchar',
    'massupdate' => 0,
    'comments' => '',
    'help' => 'tasknumber',
    'importable' => 'true',
    'duplicate_merge' => 'disabled',
    'duplicate_merge_dom_value' => '0',
    'audited' => 1,
    'reportable' => 0,
    'len' => '2',


    I know type is 'varchar' but i have read somewhere that type cannot be 'int' otherwise the logic_hook don't work? Is this correct?

    Thanks for your help, I appreciate
    Kind regards,

    De Kleine Media


    SugarCRM CE v.5.2.0h
    Windows platform
    MySQL v.5.1
    phpMyAdmin - 2.11.2.2
    Apache Server v.2.0

  6. #6
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Problem counting in logic hook

    Well in that case we should alter the logic hook. This is no way to sort numbers! Change 'varchar' to 'int' and repair.
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  7. #7
    dekleinemedia is offline A Prolific Poster
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    241

    Default Re: Problem counting in logic hook

    Quote Originally Posted by dekleinemedia View Post
    Hi,

    I have the following issue;

    I have created a logic_hook for ProjectTask. It increases every time a new projecttask is created.
    This works fine, untill i create projecttask '11'.
    The counting stocks when its creating a new task above '10'
    Taskname '11' will get the same tasknumber '10' see screenshot
    Also is my sorting not working propaply see screenshot

    In my attachment you will find the logic_hook.
    Can someone please tell me what is wrong? I appreciate

    thankss
    Hi,
    I've changed the vardefs type task_number but I would like to know why the auto-increment stock when it reach '10'. Can someone please help me? Much thankss
    Kind regards,

    De Kleine Media


    SugarCRM CE v.5.2.0h
    Windows platform
    MySQL v.5.1
    phpMyAdmin - 2.11.2.2
    Apache Server v.2.0

  8. #8
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Problem counting in logic hook

    I'm pasting you attached code here for convenience...

    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class 
    add_code {

        const 
    CODE_PREFIX "";
        const 
    CODE_SUFFIX "";
        const 
    CODE_SEPARATOR "";
        const 
    CODE_FIELD "task_number";
        const 
    CUSTOM_TABLE "project_task";
        const 
    ADD_DATE "0";
        const 
    DATE_FORMAT "y";
        const 
    ZERO_PADDING 1//minimum amount of characters desired for the number. ie 4 = 0001, 3 = 001
        
    const FIRST_NUM "1"//default to start with.

        
    function add_code(&$bean$event$arguments)
        {
            require_once(
    'log4php/LoggerManager.php');

            
    //pattern to detect valid code, designed to detect non padded numbering too.
            
    $pattern "/^" self::CODE_PREFIX . (self::ADD_DATE?"[0-9]{2}":"") . self::CODE_SEPARATOR "([0-9]+)" self::CODE_SUFFIX "$/";

            
    $GLOBALS['log']->debug("add_code function fired after save.");

            if(!
    preg_match($pattern$bean->fetched_row[self::CODE_FIELD])) {

                
    $db =  DBManagerFactory::getInstance();
                
    $query "select " self::CODE_FIELD " from " self::CUSTOM_TABLE 
                         
    " where (" self::CODE_FIELD " <> '' or " self::CODE_FIELD " is not null) order by right(" self::CODE_FIELD ", 1) desc limit 1";
        
                
    $result $db->query($querytrue'Error selecting most recent ' self::CODE_FIELD ' CODE');
        
                if (
    $row=$db->fetchByAssoc($result)) {
                    
    $last_code $row[self::CODE_FIELD];
                } else {
                    
    //no codes exist, generate default - PREFIX CURRENT_YEAR SEPARATOR FIRST_NUM
                    
    $last_code self::CODE_PREFIX . (self::ADD_DATE?date(self::DATE_FORMAT):"") . self::CODE_SEPARATOR self::FIRST_NUM self::SUFFIX;
                }
        
                
    $GLOBALS['log']->debug("Last Code: " $last_code);
        
                
    preg_match($pattern$last_code$matches);
                
    $num=$matches[1];
                
    $num++;
                
    $pads self::ZERO_PADDING strlen($num);
                
    $new_code self::CODE_PREFIX . (self::ADD_DATE?date(self::DATE_FORMAT):"") . self::CODE_SEPARATOR;
        
                
    //preform the lead padding
                
    for($i=0$i $pads$i++) {
                    
    $new_code .= "0";
                }

                
    $new_code .= $num self::CODE_SUFFIX;

                
    $GLOBALS['log']->debug("New Code: " $last_code);
                
                
    //write to database
                
    $query "INSERT INTO " self::CUSTOM_TABLE " (id, " self::CODE_FIELD ") VALUES ('$bean->id', '$new_code') ON DUPLICATE KEY UPDATE " self::CODE_FIELD "='$new_code'";
                
    $result $db->query($querytrue'Error adding ' self::CODE_PREFIX ' code');
            } else {
                
    $GLOBALS['log']->debug("Code Exists...Exiting " $bean->fetched_row[" . self::CODE_FIELD . "]);        
            }
        }
    }

    ?>
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  9. #9
    dekleinemedia is offline A Prolific Poster
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    241

    Default Re: Problem counting in logic hook

    Thanks to SugarDev this problem is solved!

    See this threat.
    Kind regards,

    De Kleine Media


    SugarCRM CE v.5.2.0h
    Windows platform
    MySQL v.5.1
    phpMyAdmin - 2.11.2.2
    Apache Server v.2.0

  10. #10
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Problem counting in logic hook

    je weet tog :P
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Filling in HTML field thorough logic hook problem
    By ishaan in forum Developer Help
    Replies: 6
    Last Post: 2009-06-18, 12:02 PM
  2. Db query problem from logic hook
    By ishaan in forum Developer Help
    Replies: 2
    Last Post: 2009-05-22, 08:02 PM
  3. Logic-hook problem - Teams
    By Spinaker in forum Help
    Replies: 17
    Last Post: 2009-03-30, 11:14 AM
  4. I have problem regarding logic hook
    By cryptex in forum Developer Help
    Replies: 6
    Last Post: 2008-12-02, 06:41 AM
  5. logic hook problem with workflow and customizations
    By danisugar in forum Developer Help
    Replies: 9
    Last Post: 2008-03-05, 04:30 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
  •