I’m trying to run “Instead of update” on beforeProcessDeltaChange () and replace some values of finalRow in run time according to value of UpdatedBy field.
I was thinking that there might be some overlapping on beforeProcessDeltaChange () , but in a debugging screen which showing Old and New values , the values are different if been changed.
May be it is a bit confusing, because in the last script I’m just trying to run update to get it going and see if it works from simple update without conditions :
There is no such thing as “Instead of update”. The script is executed and then the update is applied by the server.
Even more, the script you tried to use not only will crash due to recursive Products table update, it will be useless because any update you make via the lda.update(...) call (which is misformed btw) will be overwritten when the original delta will be applied.
Also please remember that accessing originalRow / finalRow properties is extremely expensive because it implies a database SELECT operation.
The script you MIGHT want to use looks as this one:
// Called before each change is applied to the database
function beforeProcessDeltaChange(delta, change, wasRefreshed, canRemove)
{
// Applies only to the Products table
if (delta.name !== 'Products') {
return;
}
// Applies only to UPDATE operations
if (!change.isUpdate) {
return;
}
// Reject ReducedDelta operations
if (delta.isReduced) {
fail('Reduced Deltas are not allowed on the table Products');
}
// Here change.newRow contain values that will be assigned to the database table row
// Calculate what's needed
change.newValues['App2_Qty'] = change.newValues['UpdatedBy'] + '-QWERTY';
}
You can access these values only if they were sent from the client. If the client didn’t sent them you’ll need to use the .originalRow property.
F.e.:
// Called before each change is applied to the database
function beforeProcessDeltaChange(delta, change, wasRefreshed, canRemove)
{
// Applies only to the Products table
if (delta.name !== 'Products') {
return;
}
// Applies only to UPDATE operations
if (!change.isUpdate) {
return;
}
// Reject ReducedDelta operations
if (delta.isReduced) {
fail('Reduced Deltas are not allowed on the table Products');
}
// Here change.newRow contain values that will be assigned to the database table row
// Calculate what's needed
change.newValues['App2_Qty'] = change.originalRow['UpdatedBy'] + '-QWERTY';
}