jcook331
15th February 2006, 23:55
I need to be able to tell if a user has changed any field on a type 1 form. Is there any other way to do this besides taking a snapshot of field values before input and comparing them to the field values before writing the record? I was thinking there was a Baan function that did this.
loveubaan
16th February 2006, 06:36
U CAN WRITE UR PART OF CODE IN THE WHEN.FIELD.CHANGES SECTION
LIKE
eg:
field.abc:
when.field.changes:
message("Field Values Changed")
NPRao
16th February 2006, 09:20
I need to be able to tell if a user has changed any field on a type 1 form.
Are they all table fields or form fields ?
Is there any other way to do this besides taking a snapshot of field values before input and comparing them to the field values before writing the record?
You can use rcd.tablename, for the record buffer of table. You can also use the other functions in field.all section and getting the field name with fattr.currfld, and using changed() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_variables_checking_changes_changed)
Also, refer to - on.old.occ() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_form_and_form_field_operations_on_old_occ)
Back to basic Q, what is the requirement?
jcook331
16th February 2006, 16:37
The fields on the form are all table fields. The requirement that I'm trying to meet is that if a person changes any field on the form then that person's user ID gets attached to the record. The record needs to show the last person that made a change to the record. If someone went in and made a change, but backed that change out before saving I would not want to change the user ID. However, if a change was made and then saved then I want the user ID field to be changed.
NvpBaaN
16th February 2006, 17:45
why not do this in before.rewrite? this event will be fired only when there is a change to an existing record, and only when the change is about to be committed to DB.
Regards.
jcook331
16th February 2006, 19:23
I thought of that too, but I found that if I made a change to a field, tabbed out of the field and then went back and put the original value back in the field (before saving) it still executed the rewrite. The users only want the user ID changed if the values are actually changed when the record is saved. I was able to make this work by putting the field values on save in temp variables and comparing them to the original values using the on.old.occ() function. There was quite a bit of overhead in creating 20 or so temp variables and then comparing them, buy it worked very well for what I was trying to do. Thanks for all the input.
lbencic
16th February 2006, 19:33
Well, they should have hit the Undo in that case! Of course, can't tell a user that I guess. Just want to throw in that saving that last user modified is, in my experience, kind of un reliable. Because, user A may go in and make significant changes. User B then goes in 2 minutes later and does something very minor. User B then gets the blame when all ** breaks loose.
Better to have a history table if this is so very important. Every change (before write/rewrite and delete) gets a call to update the history table with the new values and user id / timestamp.... this does not mean your theory is not correct, you can use it to NOT write to history if they change a value then change it back and save...
Of course, I may be misunderstanding what you are trying to track, so, whatever works for you!
NPRao
16th February 2006, 19:45
The record needs to show the last person that made a change to the record. If someone went in and made a change, but backed that change out before saving I would not want to change the user ID. However, if a change was made and then saved then I want the user ID field to be changed.
Better to have a history table if this is so very important. Every change (before write/rewrite and delete) gets a call to update the history table with the new values and user id / timestamp.... this does not mean your theory is not correct, you can use it to NOT write to history if they change a value then change it back and save...
You can setup this table to be audited and you can get all the insert/modify/delete information. You don't have to reinvent the wheel.
jcook331
20th February 2006, 16:59
The audit was considered, but they want to be able to look at their screen and see "who was the last person to touch this record". Ask and they shall receive. Of course, I'll have to change it next week when they change their minds. Thanks again for the help.
NPRao
20th February 2006, 20:48
Refer to the functions -
string aud_get_tran_tuname( string tran_hdr() )
This returns the BAAN user name of the user who performed the transaction.
long aud_get_tran_uuid( string tran_hdr() )
This returns the UNIX user id of the user who performed the transaction.
Macros - Audit Transaction Header (http://www.baanboard.com/programmers_manual_baanerp_help_functions_aud_macros_transaction_header)