Results 1 to 5 of 5

Thread: field with autoincrement

  1. #1
    Cata_bRc is offline Sugar Community Member
    Join Date
    Nov 2010
    Posts
    17

    Default field with autoincrement

    Hy,
    if anyone could help me I would be very grateful.
    I need a field with autoincrement like case_number
    I have a module with orders and I need a field order_number with autoincrement
    first order number field would be 1 next 2 ... 112,113
    Can anyone help me please?
    Thank you very much

  2. #2
    eitrix's Avatar
    eitrix is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Serbia
    Posts
    396

    Default Re: field with autoincrement

    example:

    module: orders
    field: order_num_c (created from studio integer)

    make before save logic hook on that module and function can go like:
    PHP Code:
    function orderIncrement($bean,$event,$arg){

    // check if record is new, only do this on new records
    if($bean->id != $bean->fetched_row['id']{
    $db //make db object here for whatever you use

    $query "SELECT order_num_c FROM orders_cstm WHERE deleted = 0 ORDER BY order_num_c DESC LIMIT 0,1";

    // run query example mysql
    $resullt $db->query("query");

    // get your result row as associative array
    // if no result assign 1
    if($result == false){
    $bean->id 1;
    }elseif(
    $row $result->fetch_assoc()){
    // assign value if you did get result
    $bean->id $row['order_num_c'] +1;
    }else{
    die(
    "Error in db query");
    }
    }

    something like this
    CRM Software Engineer
    Eontek - www.eontek.rs

  3. #3
    Cata_bRc is offline Sugar Community Member
    Join Date
    Nov 2010
    Posts
    17

    Default Re: field with autoincrement

    I will try it
    Thank you very much

  4. #4
    rakeshray is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Hyderabad (India)
    Posts
    313

    Default Re: field with autoincrement

    hi
    Simply use following code.............. in vardefs..........

    In a custom module I had the following in vardefs

    'pay_no' =>
    array (
    'required' => '1',
    'name' => 'pay_no',
    'vname' => 'LBL_TIMENO',
    'type' => 'int',
    'massupdate' => 0,
    'len' => '11',
    'auto_increment'=>true,

    ),

    and

    'indices' => array (
    array('name' =>'pay_no' , 'type'=>'unique' , 'fields'=>array('pay_no')
    ),),

  5. #5
    cedcas is offline Member
    Join Date
    Sep 2009
    Posts
    18

    Default Re: field with autoincrement

    Hello Rakeshay,

    I placed those two sets of codes into my module's vardefs.php but not getting any values on the field. Is there anything else to make this to work?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Autoincrement value in a custom integer field
    By olemo in forum Developer Help
    Replies: 3
    Last Post: 2010-12-22, 01:51 AM
  2. Adding Autoincrement field to child module
    By j.lagos in forum Developer Help
    Replies: 3
    Last Post: 2008-09-30, 12:38 PM
  3. How can I create an autoincrement field?
    By jmcalderond in forum Help
    Replies: 4
    Last Post: 2008-06-11, 03:45 PM
  4. Creating autoincrement custom field
    By joshmark in forum Help
    Replies: 4
    Last Post: 2006-12-28, 11:18 AM
  5. How to add autoincrement field
    By Proware in forum Help
    Replies: 3
    Last Post: 2006-07-12, 12:35 AM

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
  •