ben.kansas
24th September 2015, 22:28
Hi All,
I am trying to increment a Sequence number in a custom session when the user chooses to insert a new record. Basically, I want a default value placed in the Sequence Number that the user can't change. The Sequence is part of the Key so it should have a unique value.
This is what I am attempting:
choice.add.set:
before.choice:
tdcgs630.sern = get.sern()
display.all()
function domain tcsern get.sern()
{
SELECT tdcgs630.sern
FROM tdcgs630
WHERE tdcgs630.dtyp = tdcgs.dtyp.cio
AND tdcgs630.seri = :tdcgs630.seri
AND tdcgs630.docn = :tdcgs630.docn
ORDER BY tdcgs630.sern DESC
AS SET WITH 1 ROWS
SELECTDO
sequence = tdcgs630.sern + 1
SELECTEMPTY
sequence = 1
ENDSELECT
return(sequence)
}
However, after the before.choice section executes the sequence number on the form results in a "0."
Any thoughts on how I might increment the sequence number?
Thanks,
Ben
kevalghelani
25th September 2015, 08:20
I haven't used before.choice section of add.set for incrementing sequence.
Instead i prefer before.new.object section that works fine for me.
you can try using before.new.object section like:
before.new.object:
SELECT tdcgs630.sern
FROM tdcgs630
WHERE tdcgs630.dtyp = tdcgs.dtyp.cio
AND tdcgs630.seri = :tdcgs630.seri
AND tdcgs630.docn = :tdcgs630.docn
ORDER BY tdcgs630.sern DESC
AS SET WITH 1 ROWS
SELECTDO
tdcgs630.sern = tdcgs630.sern + 1
SELECTEMPTY
tdcgs630.sern = 1
ENDSELECT
vahdani
25th September 2015, 12:04
Hi Ben,
this depends on which Baan Version you are on.
in Baan4 is you do something like this:
field.tdcgs630.sern:
before.field:
if tdpur041.pono = 0 and choice <> def.find then
tdcgs630.sern = get.next.sern()
endif
function domain tcsern get.next.sern()
{
long last.sern
SELECT max(tdcgs630.sern):last.sern
FROM tdcgs630
WHERE tdcgs630.dtyp = tdcgs.dtyp.cio
AND tdcgs630.seri = :tdcgs630.seri
AND tdcgs630.docn = :tdcgs630.docn
SELECTDO
SELECTEMPTY
last.sern = 0
ENDSELECT
return(last.sern + 1)
}
In LN the prefered way is to do this in DAL:
dal.field.depends.on( "tdcgs630.sern",
HOOK_UPDATE, "tdcgs630.dtyp",
"tdcgs630.seri",
"tdcgs630.docn")
function extern void tdcgs630.sern.update()
{
long last.sern
SELECT max(tdcgs630.sern):last.sern
FROM tdcgs630
WHERE tdcgs630.dtyp = tdcgs.dtyp.cio
AND tdcgs630.seri = :tdcgs630.seri
AND tdcgs630.docn = :tdcgs630.docn
SELECTDO
SELECTEMPTY
last.sern = 0
ENDSELECT
tdcgs630.sern = last.sern + 1
}
ben.kansas
25th September 2015, 17:22
Thanks, guys.
I went with DAL approach as I am already using it. I must have had a serious brain block as I didn't see this earlier.
Cheers,
Ben
ben.kansas
25th September 2015, 18:02
Actually, I was a little hasty there.
My records appear in a list window. It is possible to tab through all the fields and start a new record without saving the records to the DB from the buffer. So the new record gets the same value as the previous record in the buffer because they haven't been written to the DB.
Is there a way to force the session to write a record to the DB, when "tabbing" to a new record?
bhushanchanda
25th September 2015, 18:15
Just use the following code to force save record on tab to new occurrence.
after.form.read:
enable.save.on.occ.change ()
mark_h
25th September 2015, 18:23
In 4c4 without saving the record we do something like this and yes I know he is using dal, but I would think you could the same thing without forcing a save after each record.
field.tdcyc010.locf:
before.input:
read.serial.number()
search.last.used.seqn.on.screen()
tdcyc010.sern = serial.number + 1
display("tdcyc010.sern")
function read.serial.number()
{
serial.number = 0
select max(tdcyc010.sern):serial.number
from tdcyc010
where tdcyc010._index1 = {:tdcyc010.cycg,:tdcyc010.cwaf, :tdcyc010.cwat }
as set with 1 rows
selectdo
endselect
}
function search.last.used.seqn.on.screen()
{
for occ.no = 1 to (filled.occ - 1)
do.occ(occ.no,check.last.used.sern)
endfor
}
function check.last.used.sern()
{
if tdcyc010.sern > serial.number then
serial.number = tdcyc010.sern
endif
}
ben.kansas
25th September 2015, 18:38
Thanks for the replies.
The enable.save.on.occ.change() worked perfectly.
Mark, I'll keep that solution in mind for our Baan IV systems. We still have a number of sites on Baan IV.
günther
28th September 2015, 07:42
@Mark: In your case, do.occ.without.update() would be better.
Regards
Günther