I think that could be very useful having some kind of object that could allow us to retrieve the original record in the table events.
I mean that when a table event, for example onRecordUpdate, be triggered we could have an object with the original data.
Why? I´m trying to get this:
Suppouse a table like the order_lines. Once a record is updated we have to change some data in other tables (stocks, etc) so we could say in the onRecordUpdate event stock=(stock+oldData.quantity)-newData.quantity.
Maybe you have some other way to get this.
Thanks in advance.
actually you have this information at the onRecordUpdate event.
Just check if there are any changes using: databaseManager.hasRecordChanges(record)
If this is check passed you can get a dataset containing differences using: var $dataset = databaseManager.getChangedRecordData(record);
we use this succesfully
mboegem:
actually you have this information at the onRecordUpdate event.
Just check if there are any changes using: databaseManager.hasRecordChanges(record)
If this is check passed you can get a dataset containing differences using: var $dataset = databaseManager.getChangedRecordData(record);
we use this succesfully
Yes I have seen getChangedRecordData() but I still think that is not the best way. At least the way the changed data is returned. I would prefer a complete dataSet with the old values. Right now it returns an array only with the fields changed and giving the old an new values, this way you have to play with an array and find out the fields that have been changed. If I have a record with a field for quantity and a field for price I have to check if the quantity have been modified to update it´s related data, if the price have been modified to do so, etc. I think that is not the fastest way to do things and we are talking about a RAD Tool.
jasantana:
I think that is not the fastest way to do things and we are talking about a RAD Tool.
I agree this is not the fastest way, but I’m sure you got your reasons you want to go this way.
RAD Tool and go fast means: use calculations & aggregates, but this way has its downsides as well.
We’re using the onRecordUpdate for over 2 years, where we developed standard methods to do this.
the methods use information from metadata records to determine what to do.
Concerning the stock overview we use sql views to show this.
This way we don’t have to deal with updates/locks/etc.
Downside is: an sql view is a db result of which Servoy has no knowledge when data is changed.
Every time you want to show this you have to refresh the foundset from the server.
We’re using the onRecordUpdate for over 2 years, where we developed standard methods to do this.
the methods use information from metadata records to determine what to do.
Concerning the stock overview we use sql views to show this.
This way we don’t have to deal with updates/locks/etc.
Downside is: an sql view is a db result of which Servoy has no knowledge when data is changed.
Every time you want to show this you have to refresh the foundset from the server.
Could you please share some examples?
Thanks in advance.
jasantana:
Yes I have seen getChangedRecordData() but I still think that is not the best way. At least the way the changed data is returned. I would prefer a complete dataSet with the old values. Right now it returns an array only with the fields changed and giving the old an new values, this way you have to play with an array and find out the fields that have been changed. If I have a record with a field for quantity and a field for price I have to check if the quantity have been modified to update it´s related data, if the price have been modified to do so, etc. I think that is not the fastest way to do things and we are talking about a RAD Tool.
But what do you want then?
How would you do it that is so much faster? You have all the data.
if you really want to have something like record.getChangedValue(dataprovider)
then you can make that very easy…
Make 1 helper method with that converts the dataset to a array of dataprovider->old data
function onRecordUpdate(record)
{
var changedArray = getChangedArray(record);
if (changedArray["quantity")) { // do you stuff}
}
functin getChangedArray(dataset)
{
var array = new Array();
for(var i =1;i<=dataset.getMaxRowIndex();i++)
array[dataset.getValue(i,1)] = dataset.getValue(i,2);
return array;
}
Make 1 helper method with that converts the dataset to a array of dataprovider->old data
Thanks Johan, you light me the way
I have modified your code to get a complete array:
function onRecordUpdate_socios(record) {
var oOldData=getOldDataArray(record);
application.output(oOldData.nombre)
return true
}
function getOldDataArray(oRecord) {
var aProviders = oRecord.foundset.alldataproviders
var aOldData = new Array();
var dataSet=oRecord.getChangedData()
// First we put all the fields (with new data)
for (var i=0;i<=aProviders.length;i++)
aOldData[aProviders[i]] = oRecord[aProviders[i]]
// Now set the old data
for(var i =1;i<=dataSet.getMaxRowIndex();i++)
aOldData[dataSet.getValue(i,1)] = dataSet.getValue(i,2);
return aOldData
}