Alpha DevCon 2018
Results 1 to 7 of 7

Thread: Code to halt autoincrement field

  1. #1
    "Certified" Alphaholic
    Real Name
    Thomas Patten
    Join Date
    Apr 2000
    Location
    Duluth, MN
    Posts
    1,443

    Default Code to halt autoincrement field

    Is there code to halt the autoincrement set in Field Rules; run append operation, then turn Autoincrement back on?

    I want to append records from a backup, so I need to keep the autoincrement from firing. I am selecting, "Add Unique, Replace Existing" and referencing the autoincrement field.

    Currently I accomplish this by manually turning off the Autoincrement in Field Rules, running the append operation, then turning it back on again.

    Thanks,

    ~ Tom

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,854

    Default Re: Code to halt autoincrement field

    Off
    Code:
    tbl = table.open("yourtablename")
    ruls = tbl.rules_get()
    ruls.change_begin()
    ruls.autoincrementfieldname.Data_Type = "User"
    ruls.change_end()
    tbl.close()
    On
    Code:
    tbl = table.open("yourtablename")
    ruls = tbl.rules_get()
    ruls.change_begin()
    ruls.autoincrementfieldname.Data_Type = "Autoinc"
    ruls.change_end()
    tbl.close()
    Last edited by Stan Mathews; 12-13-2017 at 05:34 PM.
    There can be only one.

  3. #3
    "Certified" Alphaholic
    Real Name
    Thomas Patten
    Join Date
    Apr 2000
    Location
    Duluth, MN
    Posts
    1,443

    Default Re: Code to halt autoincrement field

    Stan - Sorry but I can't get it to work when substituting the following:

    (I put the following on a button to test)
    Code:
    tbl = table.open("Ser_Arc")
    ruls = tbl.rules_get()
    ruls.change_begin() 
    ruls.ARC_ID.C = "User" - doesn't like this line
    ruls.change_end()
    tbl.close()
    What am I doing wrong? The Arc_id field is currently "Auto Increment"

    ~ Tom

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,854

    Default Re: Code to halt autoincrement field

    Not sure what the "C" is in

    ruls.ARC_ID.C = "User" - doesn't like this line

    should be

    ruls.ARC_ID.Data_Type = "User"
    There can be only one.

  5. #5
    "Certified" Alphaholic
    Real Name
    Thomas Patten
    Join Date
    Apr 2000
    Location
    Duluth, MN
    Posts
    1,443

    Default Re: Code to halt autoincrement field

    Works GREAT.

    I thought "Data_Type" was looking for Character, Number, Date...

    Thanks again Stan.

    ~ Tom

  6. #6
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,854

    Default Re: Code to halt autoincrement field

    Welcome.

    All sorts of things you can do.

    Code:
    fld = "myext,n,8,2"
    table.Add_Fields("atest",fld)
    tbl = table.open("atest")
    ruls = tbl.rules_get()
    ruls.change_begin()
    ruls.MYEXT.Data_Type = "Calc"
    ruls.MYEXT.Calc = "7*9" 'nonsense calculation for illustration
    ruls.change_end()
    tbl.Recalc_CalcFields()
    tbl.close()
    Perhaps a more useful example. Suppose you have a summary or crosstab result table (atest) to which you want to add a calculated field (myext) multiplying the values in the second and third fields.

    Code:
    fld = "myext,n,8,2"
    table.Add_Fields("atest",fld)
    tbl = table.open("atest")
    fld1 =  tbl.field_get(2).name_get() 'second field counting left to right
    fld2 =  tbl.field_get(3).name_get() 'third field counting left to right
    ruls = tbl.rules_get()
    ruls.change_begin()
    ruls.MYEXT.Data_Type = "Calc"
    ruls.MYEXT.Calc = fld1+"*"+fld2
    ruls.change_end()
    tbl.Recalc_CalcFields()
    tbl.close()
    Last edited by Stan Mathews; 12-14-2017 at 12:47 PM.
    There can be only one.

  7. #7
    "Certified" Alphaholic
    Real Name
    Thomas Patten
    Join Date
    Apr 2000
    Location
    Duluth, MN
    Posts
    1,443

    Default Re: Code to halt autoincrement field

    A BONUS!!

    Thanks and All the best of the season to you.

    ~ Tom

Similar Threads

  1. Dialog2 and autoincrement field
    By Cristiano in forum Application Server Version 11 - Web/Browser Applications
    Replies: 3
    Last Post: 05-07-2013, 08:28 AM
  2. Autoincrement "ticket reference code"
    By GuyAtLarge in forum Alpha Five Version 9 - Desktop Applications
    Replies: 12
    Last Post: 03-02-2009, 01:55 PM
  3. Halt Script = Halt A5v7?
    By CALocklin in forum Alpha Five Version 7
    Replies: 10
    Last Post: 12-01-2005, 06:00 PM
  4. autoincrement field
    By dcorcoran in forum Alpha Five Version 6
    Replies: 9
    Last Post: 05-01-2005, 09:18 AM
  5. Autoincrement field
    By Scott Rusoff in forum Alpha Five Version 5
    Replies: 2
    Last Post: 02-09-2003, 04:40 PM

Posting Permissions

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