Old values to be retrieved in Table Events

Discuss all feature requests you have for a new Servoy versions here. Make sure to be clear about what you want, provide an example and indicate how important the feature is for you

Old values to be retrieved in Table Events

Postby jasantana » Mon Aug 30, 2010 6:03 pm

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.
Best regards,
Juan Antonio Santana Medina
jasantana@nephos-solutions.co.uk
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 554
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: Old values to be retrieved in Table Events

Postby mboegem » Tue Aug 31, 2010 12:18 pm

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
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1524
Joined: Sun Oct 14, 2007 1:34 pm
Location: Hoofddorp, The Netherlands

Re: Old values to be retrieved in Table Events

Postby jasantana » Tue Aug 31, 2010 12:58 pm

mboegem wrote: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.
Best regards,
Juan Antonio Santana Medina
jasantana@nephos-solutions.co.uk
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 554
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: Old values to be retrieved in Table Events

Postby mboegem » Tue Aug 31, 2010 1:52 pm

jasantana wrote: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.
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1524
Joined: Sun Oct 14, 2007 1:34 pm
Location: Hoofddorp, The Netherlands

Re: Old values to be retrieved in Table Events

Postby jasantana » Tue Aug 31, 2010 5:09 pm

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.
Best regards,
Juan Antonio Santana Medina
jasantana@nephos-solutions.co.uk
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 554
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: Old values to be retrieved in Table Events

Postby jcompagner » Tue Aug 31, 2010 7:47 pm

jasantana wrote: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

Code: Select all
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;
}
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8212
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Old values to be retrieved in Table Events

Postby jasantana » Wed Sep 01, 2010 1:58 pm

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:
Code: Select all
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
}
Best regards,
Juan Antonio Santana Medina
jasantana@nephos-solutions.co.uk
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 554
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom


Return to Discuss Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest