I’m in the process of finalizing a preview chapter (from the upcoming book Jim and I are writing on Data Abstract fore Xcode) that discusses the scripting API. this should be available within the next week, alongside a new round of DA builds with a lot if improvements and fixes to Scripting support. in the mean time, here are a couple of example snippets:
function beforeProcessDeltaChange(delta, change, wasRefreshed, canRemove)
{
if (change.isUpdate) {
if (change.newValues[“Address”] == “Happy St.”) fail(“Can’t move to Happy Street!”);
}
if (change.isInsert || change.isUpdate)
{
if (finalRow[“Country”] == “USA” & finalRow[“State”] == null)
fail(“A state is required for addresses in the U.S.”);
}
}
And, yes, you can of course define your own functions inside the scripts, and reference tose form the default event handlers. just make sure those function names don’t conflict with the handlers defined by DA or Relativity (ie, don’t name them beforeProcessDeltaChange() or like any of the other names you see in the Add Event dropdown).
Can I use a function I have in my service in the script.
I need to generate a number something like this
select max(number) + 1 from table where project = 1
I have made a function in my service which gives the correct number, which I need to pass as a parameter to my insert wuery and I like to do this with a script. Is this possible?
good question. in a custom DA server, you could probably work with the core RemObjects Script components to inject extra functionality into the scope for your server-side DA scripts. this is not my area of expertise, i’ll get someone else to reply to this. Follow-up questions might be better suited in http://connect.remobjects.com/categories/script.
sorry, my bad, yes. i think for DA/Delphi, you’ll have to deal directly with the Microsoft ActiveScript API to inject your own things into the scripting context. it’s certainly doable, but outside of our API scope.
Is there a tutorial of how to implement java script in a delphi server?
Ho do I use the beforepost for example.
There is a sample ‘Scripting’ in \RemObjects Samples\Data Abstract for Delphi\Scripting\ that illustrates this. It uses DASampleServer as a server, you canl look at its sources in \RemObjects Samples\Data Abstract for Delphi\Server
In the Schema Modeler right-click on the Scripting.Clients table and choose Business Rules to explore event handlers.
I got it working but I don’t like the error message text so I decided to modify that
in my client in the scripting provider I put code in the onerror event
now I first get my error and the n the default error
In the uDAEMCAscritping I found this code
on E: ScriptException do begin
if Assigned(fOnError) then fOnError(E);
raise;
if I use this in the busines rules for client and server
function beforePost(deltachange)
{
If (deltachange.newValues[‘MTTAGID’] = ‘’)
fail(‘Tag no. must have a valid value’);
}
I get message "The script you are executing is taking longer than expected to run. …"
and my client application is unreponsive after I clicked end
I got it working but I don't like the error message text so I decided to modify that
in my client in the scripting provider I put code in the onerror event
now I first get my error and the n the default error
In the uDAEMCAscritping I found this code
on E: ScriptException do begin
if Assigned(fOnError) then fOnError(E);
raise;
you can set your message in Error event like
procedure TServerDataModule.DAEcmaScriptProvider1Error(
aEcmaScriptProvider: TDAEcmaScriptProvider; aError: ScriptException);
begin
aError.Message := ‘my message’;
end;
We got skinning in our app so I just want to handle the error myself so I got a skinned messagebox.
I use
with messageDlg(aError.Message, mtError, [mbOk],0); to show the error message
Exception is needed here
As I understand, you have skinned client application.
In this case, you can hide or replace exception with raiseException := False in Table.OnScriptError event