Changing record data in an onRecordUpdate handler

I am new to Servoy… liking it very much so far.

I have a requirement for an onRecordUpdate handler to set a value for “last_update_date” and “last_updated_by” columns.

I expect that in the onRecordUpdate function I could either modify the “record” that is passed in as an argument… or, I could modify “last_update_date” and “last_updated_by” columns on forms, perhaps even “off screen” columns, and assume that Servoy will “do the right thing”… or I could use raw SQL.

I suspect there are alternatives that haven’t occurred to me.

Some of these seem potentially messy since Servoy might not be expecting side effects from this function. And raw SQL seems like brute force.

Is there a “best practice” approach?

Thanks.

Larry Talley

i think that you need something like attaching a global method to OnRecordUpdate event

function onRecordUpdate_tablename(record) {
	// TODO Auto-generated method stub
	// throw exception to pass info to handler, will be returned in record.exception.getValue() when record.exception is a DataException
	if (not_valid) throw 'cannot update'
record.last_update_date=new date()
record.last_update_by=globals.myusername
	// return boolean to indicate success
	return true
}

BUT Another way of doing that is that you could simply let Servoy managing that for you:
for each of fields you can choose different system values in the combobox in the autoenter properties
for last_update_date set “modification datetime”
for last_update_by set “modification username” or “modification user uid”

Hope that could hep you

Thank you, just what I was looking for, I guessed maybe Servoy could manage it for me, I just didn’t know where to look. Thanks for the tip.

BUT Another way of doing that is that you could simply let Servoy managing that for you:
for each of fields you can choose different system values in the combobox in the autoenter properties
for last_update_date set “modification datetime”
for last_update_by set “modification username” or “modification user uid”

record.last_update_date=new date()

BTW: this code is not correct and not be best: First of all, to make it valid code, it should be:

record.last_update_date=new Date()

But, this will insert the time on which the client runs and clients can fiddle with their time.

Always use application.getServerTimeStamp() when working with dates/times that you store.

Also, the auto enter settings for creation/modification datetime van the option to specify the server date/time

Paul

:D Thanks!