This topic is locked

Automatic number generation visible in field

5/1/2007 5:47:10 PM
ASPRunnerPro General questions
M
mfred author

I have a need to have a justomer easily retrieve a job number. This can't be from an auto number in the database because that would require the user to look it up in the list. They need to see the job number eith on the add new page or on submission, whichever is easier.

Sergey Kornilov admin 5/1/2007

You cannot assign a job number to record that don't exist yet.
Use autonumber field and AfterAdd event that retrieves this number and displays it on the page.

M
mfred author 5/2/2007

Regarding "autonumber field and AfterAdd event that retrieves this number and displays it on the page", Are these features in ASPRunner or do I need to plugin code?

F
funklet 5/2/2007

Regarding "autonumber field and AfterAdd event that retrieves this number and displays it on the page", Are these features in ASPRunner or do I need to plugin code?


The autonumber is the field in the database that automatically inserts a new number when a record is added.

AfterAdd is the "After Record Added" event in ASPRunner on Events (Step 11) (if you do not have events then you will need a later version of ASPRunner)
The easy way to do this is to use the code:
[codebox]Sub AfterAdd()

'** Display a message on the Web page ****
strSQL = "select top 1 jobnumber from jobstable order by jobnumber desc"

Set rsJob = server.CreateObject ("ADODB.Recordset")

set rsJob = dbconnection.execute strSQL

if rsJob.eof = false then

message = "Your job has been created with job number: " & rsJob.fields("jobnumber")

end if

rsJob.Close

set rsJob = nothing

End Sub[/codebox]
This code has flaws, one of them is that potentially if two jobs were added simultaneously (this would have to be within milliseconds) both users may well end up having the same jobnumber reported even though the jobs would be saved correctly in the table.

The way to solve this problem is to include the sessionID (or other locally produced session constant) of the user who adds the code so that his can be included as a where clause to the SQL statement.
I hope this is of help.
Kind regards.