Catch Schema script fail function

Hello,
I have a script defined in the Schema:


function beforeProcessDeltaChange(delta, change, wasRefreshed, canRemove)
{ 
	if (!change.isDelete && !change.newValues['name']) { 
		fail('Name is required');
  	}

	if (!change.isDelete ) {
        change.newValues['modified'] = new Date().toString();
    }
	
	if (change.isInsert) {
	    change.newValues['created'] = new Date().toString();
	}
}

Can I catch exceptions (fail function) on the client side (Delphi) to show my error dialog and have some custom code?

Is there a better way to do validation on the server side?

Hi,

You can catch exception in the OnProcessError event of Business Processor component.

You can drop the Business Processor component to service in design-time and set handler via Object Inspector or assign handler in the DataAbstractService.OnBusinessProcessorAutoCreated event in run-time like

procedure TDataService.DataAbstractServiceBusinessProcessorAutoCreated(
  aSender: TRORemoteDataModule; BusinessProcessor: TDABusinessProcessor);
begin
  if BusinessProcessor.ReferencedDataset = 'mytable' then
    BusinessProcessor.OnProcessError := MyProcessError;
end;

Is this server-side code - I need to catch an exception on the client side (Delphi)?

Hi,

It was service-side code. In the OnProcessEvent event you can raise own exception if needed.

On client-side, you can use Reconcile Dialog component. We have VCL- and FMX-based versions. TDAVCLReconcileProvider or TDAFMXReconcileProvider can be assigned to RemoteDataAdapter.ReconcileProvider.

Check FailureBehavior page - you can specify default behavior for processing of such errors on client-side.

I don’t want to show Reconcile Dialog, is it possible to only catch the exception thrown from the fail function?

Hi,

set RemoteDataAdapter.FailureBehavior to fbRaiseException.

You can catch exception like

try
  table.ApplyUpdates;
except
  on E: EDAUpdatesFailedException do ....
end;

Thank you
that is working, but now I need to have a separate RDA for every DAMemDataTable - is this ok setup?

Hi,

RDA can handle one or several tables.
it’s ok to have a separate RDA for every table.