alexpreyer
30th September 2010, 14:44
I have a multi occurence session, where, at the end of each line, a check should be done if the sum of some of the fields is 100. If not a message should appear.
How do I know when the user jumps to the next occurence? A main.table.io - before.write check does not work.
mark_h
30th September 2010, 15:53
When do you want to check? At insert time. I have a at least one program which does this based off a set of records - so I have my check in several locations. The question is the by individual record or a set of records?
choice.start.set:
before.choice:
verify.allocations(false)
after.choice:
on.main.table(check_found)
if found then
execute(find.data)
endif
choice.first.view:
before.choice:
verify.allocations(false)
choice.last.view:
before.choice:
verify.allocations(false)
choice.def.find:
before.choice:
verify.allocations(false)
choice.find.data:
before.choice:
verify.allocations(false)
choice.next.view:
before.choice:
verify.allocations(false)
choice.prev.view:
before.choice:
verify.allocations(false)
choice.end.program:
before.choice:
if getenv$("LOGNAME")<>"mark_h" then
verify.allocations(false)
endif
choice.abort.program:
before.choice:
verify.allocations(false)
mark_h
30th September 2010, 15:56
PS - I also built a check in so at least my user id could exit the session without having to kill it if the allocations were incorrect. In my case each allocation has an expiring date. Sometimes the user gets confused and does not enter the correct allocations and aborts the session.
alexpreyer
30th September 2010, 15:57
The best moment would be when leaving the occurence (jumping to a new line). Or before leaving the occurence maybem allowing only moving to the next line if the sum is 100.
günther
30th September 2010, 16:03
Hi Alex.
Occurrences are buffered; they get flushed to disk / database when you leave the session, press the save button, or when you insert some records and you reach the end of the screen (maybe some more events).
Here is a code snipped (untested); to keep it simple I made one assumption: Add a field "flag" to your table.
declaration:
double total
main.table.io:
after.read:
<table>.flag = 0
before.write:
<table>.flag = 1
before.rewrite:
<table>.flag = 1
functions:
function check.occurances()
{
long i
total = 0.0
| calculate the sums "on the screen"
for i = 1 to fattr.occurnr
do.occ.without.update( check.occ, i )
endfor
| add the sums already written to db
on.main.table( check.db )
}
function check.occ()
{
if <table>.flag = 0 then
total = total + <table.field>
endif
}
function check.db()
{
select ...
from <table>
where ...
and <table>.flag = 1
selectdo
....
total = total + <table.field>
endselect
}
Günther
mark_h
30th September 2010, 16:17
Well on the last field of input you could always do a check.input. So lets say you had item and 3 percentage fields(field1, field2, field3). On field3 you could do a check.input to make sure field1,2,3 add to 100 - if not give a message and do a input.again. That would be one check.
Then if they want to randomly change percentages on the form and hit the save button. Maybe a check.all.input would work in choice.update.db section. Not really sure about that.
The key is knowing figuring out which events get fired depending on what button the user hits. To debug this what I will do is add in all of the sections I can think off - put a different message in each section. Then I pretend to be a "user" and do things randomly to document which messages I get when. Now the one thing I have learned is there is no stopping a user from turning off his desktop if it is not going their way. :)
alexpreyer
30th September 2010, 16:33
The main problem is, I don't know which of the 5 fields the last ist. Depending on the amount of records in another table (1 - 5) not everytime all 5 fields need to be filled.
Also, when users changing field and leaving the check has to be done.
So, I supposed the easiest way should be do the check after leaving the occurence.
günther
30th September 2010, 16:45
Hm. "After leaving the occurence" means when.field.changes (or check.input) of that input field. This event will fire for each occurrence.
Btw. I've been thinking some time about your problem. Let's say you have 100 occurances each with a quantity of 1; so its okay. Now, while writing to the database the user closes the baan client (network error, what so ever). This will give "corrupted" data, right? So you must write all data within one transaction´and you can't use the standard function.
Günther
mark_h
30th September 2010, 22:32
Hm. "After leaving the occurence" means when.field.changes (or check.input) of that input field. This event will fire for each occurrence.
Btw. I've been thinking some time about your problem. Let's say you have 100 occurances each with a quantity of 1; so its okay. Now, while writing to the database the user closes the baan client (network error, what so ever). This will give "corrupted" data, right? So you must write all data within one transaction´and you can't use the standard function.
Günther
Gunther - he would have 1 record with upto 5 fields that add up to 100.
Alex - do you know how many fields there are? I mean is that passed back or can it be determined? Then you can do a generic check on that by use for loop to add the 1 to 5 fields. Then check it against 100 - if they don't equal then pop up the message.
Can you post a screen print of the session?
sameer.don
4th October 2010, 08:39
Hi Alex,
I have faced on such requirement, check was required on amount.
Session was developed with Multi-occ form for maintaining Payment Schedule for project element. And session should not allow user to exceed the amount at header.
So code was written to validate total payment amount entered on each line.
Check applies in case if users is Inserting line, Updating Existing Line, Updating newly inserted (not saved) lines.
Check if it helps you.
field.ttmmm213.amnt:
before.input:
tmp.amnt = ttmmm213.amnt
check.input:
if choice <> update.db then
if (tot.amnt + ttmmm213.amnt - tmp.amnt) > element.amnt then
message("Total amount should not exceeed the amount of element.")
set.input.error("")
endif
endif
after.input:
tot.amnt = tot.amnt - tmp.amnt + ttmmm213.amnt
choice.update.db:
before.choice:
if tot.amnt > element.amnt then
message("Total amount should not exceeed the amount of element.")
choice.again()
endif
alexpreyer
4th October 2010, 15:03
I attached a screenshot. How many rows are used is defined in another table. I read this table on session start to get the headlines over the rows. So I know how many will be used.
I'll try the suggestion of sameer.don. Thanks.