Briefcase as a service

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.

DB table structure:

 Products ( 
      ID Char( 18 ),
      Qty Numeric( 10 ,0 ),
      App1_Qty Char( 50 ),
      App2_Qty Char( 50 ),
      App3_Qty Char( 50 ),
      App4_Qty Char( 50 ),
      App5_Qty Char( 50 ),
      UpdatedBy Integer,
      Updated TimeStamp )

On Schema it is defined as:

ID WideString( 18 )
Qty Decimal( 0 ,10 )
App1_Qty WideString( 50 )
App2_Qty WideString( 50 )
App3_Qty WideString( 50 )
App4_Qty WideString( 50 )
App5_Qty WideString( 50 )
UpdatedBy Integer
Updated DateTime

obviously ID Char( 18 ) is a Primary index

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';
}

Thank you , it works.

Can I do something like Old values say : oldValues[‘App2_Qty’] some how?

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';
}