I have a need to get a session variable to auto-increment each time a grid is submitted, and then have that value set as the default value of a specific field.
I can get the initial record value set correctly, but subsequent records in the grid will not auto-increment.
I have to "roll-my-own" auto-increment for specific reasons, and I am getting the starting value from a value in a table. When the record is saved, the next value is written back to the table, and that does work. If I open and close the grid (or re-load the web page), the session variable re-populates from the table, but if I create a new record immediately after creating a record, the session variable will not update the value for the new record. The issue I cannot achieve is to get the session variable to increment immediately and place the new value into the field when another value is a new record is created.
I have tried the following code on the CanInsertRecord event on the grid:
As you can see, I tried deleting the variable and then I re-create it on the OnGridInitialize event.
Any thoughts?
I can get the initial record value set correctly, but subsequent records in the grid will not auto-increment.
I have to "roll-my-own" auto-increment for specific reasons, and I am getting the starting value from a value in a table. When the record is saved, the next value is written back to the table, and that does work. If I open and close the grid (or re-load the web page), the session variable re-populates from the table, but if I create a new record immediately after creating a record, the session variable will not update the value for the new record. The issue I cannot achieve is to get the session variable to increment immediately and place the new value into the field when another value is a new record is created.
I have tried the following code on the CanInsertRecord event on the grid:
function CanInsertRecord as v (DataSubmitted as P, Args as p, PageVariables as p, Result as p)
with PageVariables
Result.Cancel = .f.
Result.ErrorHTML = ""
end with
dim t as p
dim session.next_number as c
t = table.open("seq_cit_no")
t.fetch_first()
t.change_begin()
vc_next_number = increment_value(t.Next_number)
t.Next_number= vc_next_number
t.change_end()
t.close()
delete session.next_number
end function
with PageVariables
Result.Cancel = .f.
Result.ErrorHTML = ""
end with
dim t as p
dim session.next_number as c
t = table.open("seq_cit_no")
t.fetch_first()
t.change_begin()
vc_next_number = increment_value(t.Next_number)
t.Next_number= vc_next_number
t.change_end()
t.close()
delete session.next_number
end function
Any thoughts?
Comment