Haggis
24th March 2003, 12:31
Hi
I have a session that the user uses to assign a Business Partner to a category. They have to go through each BP number. I was asked if it was possible to get the form to increment the BP number as you go to the next record. So if you inserted BP100001 to a category and tabbed to the next line or record it would default to BP100002?
Tried to do something in the script for along the lines of
field.tfzzz302.bpid:
before.input:
if choice = add.set then
on.main.table (get.next.bp)
tfzzz302.bpid = last.bp + 1
endif
then the function get.next.bp tries to determine the highest BP used so far, etc. But obviously the BP is not a number but a string?
Can anyone help or point me in the right direction?
Thanks
Haggis
FransG
24th March 2003, 12:50
field.tfzzz302.bpid:
before.input:
if choice = add.set then
tfzzz302.bpid = get.next.bp(last.bp)
endif
function domain tccom.bpid get.next.bp(domain tccom.bpid i.last.bp)
{
domain tccom.bpid next.bp
next.bp = ""
select tccom100.bpid:next.bp
from tccom100
where tccom100._index1 > {:i.last.bp}
order by tccom100._index1
as set with 1 rows
selectdo
endselect
return(next.bp)
}
BTW, this might be performance inefficient.
kevobr
24th March 2003, 15:03
Haggis, I think what you are after is to convert the bpid from it's string to an integer, add 1 and convert it back again.
e.g.
tfzzz302.bpid = str$( (lval(last.bpid) + 1) )
Haggis
24th March 2003, 16:28
Hi
Thanks for the suggestions guys. Fransg I have inserted your code in and it works. The only problem is getting the last BP that was inserted into the last.bp variable so it knows where to pick the next one up from. It currently puts a blank BP into the variable so I keep getting the first BP inserted everytime. I am playing around with it.
Kevobr thanks for that conversion, will give it a try now.
Thanks again
Haggis
kevobr
24th March 2003, 18:20
Haggis you need to add in a line to FransG's suggestion to set i.last.bp e.g.
field.tfzzz302.bpid:
before.input:
if choice = add.set then
tfzzz302.bpid = get.next.bp(last.bp)
i.last.bp = tfzzz302.bpid
endif
Just addding 1 to bpid would still need the check of the tccom100 table to ensure BP exists so probably best stick with FransG's solution.
FransG
25th March 2003, 08:55
Haggis,
You can keep track of the "last" business partner in the when.field.changes section. If you do an assignment in that section then it's ok, I guess.
The first time entering will return the first business partner because the "last.bp" is empty.
last.bp should be defined global for the script.
|* Declaration
domain tccom.bpid last.bp
|* Field Section
field.tfzzz302.bpid:
before.input:
if choice = add.set then
tfzzz302.bpid = get.next.bp(last.bp)
endif
when.field.changes:
last.bp = tfzzz302.bpid
|* Function section
functions:
function domain tccom.bpid get.next.bp(domain tccom.bpid i.last.bp)
{
domain tccom.bpid next.bp
next.bp = ""
select tccom100.bpid:next.bp
from tccom100
where tccom100._index1 > {:i.last.bp}
order by tccom100._index1
as set with 1 rows
selectdo
endselect
return(next.bp)
}
Because of assigning last.bp only in the when.field.changes section you'll always have the previous handled business partner.