0

Auto Numbering Issue

Good Morning

 

I have a table that i keep all my work orders in and i have one table that i keep all my product submittals in that it autonumbers when i link them together. Question i have is how do restart the number to 1.

Example

(2019-392-014) . (YEAR - PROJECT ID - Submittal auto number)

With the current configuration i am running this is what i am seeing. Every project has an unique project id

 

2019-392-001

2019-392-002

2019-392-003

2019-040-004

2019-041-005

2019-392-006

 

let y := text('Work Order Master Code');
let z := year('Current Date');
let c := cnt(select RFI where text('Work Order Master Code') = y);
let c := cnt(select RFI where year('Current Date') = z);
'RFI #' := z + "-" + y + "-" + format(c, "000")

6 replies

null
    • NIOXUS
    • 5 yrs ago
    • Reported - view

    Rushhenry - the easiest way to do this would be to use an If/Then structure to test whether or not next next record is a continuation of the current series or is it the first record in a new series.  In the example above, you would set a variable equal to the Project ID of the new record being entered.  You would then use the cnt (count) function to determine if any records already exist with that Project ID.  If the function returns a value greater than 0 (zero), then you simply increment the current highest numbered record by one and continue the sequence.  If, however, the function returns a zero, that would indicate that this is the first record in a new series for a new Project ID meaning you would then start over with the number 001 for the third segment (Submittal Auto Number).

    Your code would look something like this:

    Screen Shot 2019-04-03 at 7.17.33 AM

    Using the code block above, you might want to include a length test on the subAutoNo variable to determine how  many leading zeros are required to adhere to your YYYY-PID-### format.

    • Mconneen
    • 5 yrs ago
    • Reported - view

    @NinoxUS..   No length test needed  .. use a format(subAutoNo, "000")...   Now.. maybe a check to ensure you do not go over 999.. :) 

    • NIOXUS
    • 5 yrs ago
    • Reported - view

    Thanks Mike.

    • russhenry715
    • 5 yrs ago
    • Reported - view

    ok i have a problem getting your code to work. I have this code place "Trigger on Create". Any advise i would apprecieate it 

     

    let y := text('Work Order Master Code');

    let z := year('Current Date');

    let c := cnt(select Submittals where text('Work Order Master Code') = y);

    let c := cnt(select Submittals where year('Current Date') = z);

    'Submittal #' := z + "-" + y + "-" + format(c, "000.001")

    • Sean
    • 5 yrs ago
    • Reported - view

    A couple of problems at a glance...

    let c := cnt(select Submittals where text('Work Order Master Code') = y);

    is overwritten by the next line...

    let c := cnt(select Submittals where year('Current Date') = z);

     

    Also, the format you used will always have a "1" as the last digit regardless what the actual number is. It should be "0" in the format() function.

    • Sean
    • 5 yrs ago
    • Reported - view

    I'm going to make some assumptions...

     

    1) 'Work Order Master Code' is stored as a number since you are using the text() function

    2) Each Submittal has a unique date

    3) Work Orders can span multiple years because you check for the current year

     

    I don't know what your database structure is, but I don't know how this would work in "Trigger on create". At the very least you will need to enter a date in your Submittal table so that you can autogenerate your RFI#. I put this code in "Trigger after update" in the Date field...

     

    let t := this;
    let pId := t.'Project Id';
    let curYear := year(today());
    let subAutoNo := cnt(select RFI where 'Project Id' = pId and year(Date) = curYear);
    t.('RFI #' := curYear + "-" + format(pId, "000") + "-" + format(subAutoNo, "000"))

Content aside

  • 5 yrs agoLast active
  • 6Replies
  • 2610Views