Javascript for business rules in schema

Are there any examples on how to use javascript to do some field value validation?

something like
if FieldbyName(‘Ordernr’).isEmpty then showmessage(‘Please give a ordernr’)

Is it also possible to define your own actions to be used in the business rules?

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.

The link is the .net script section.
I want to use scripting with Delphi

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.

Thanks, logged support request as bugs://47788
Posted by Bugs for Mac

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;

In the sample I see that function beforePost(row)
but when I chose beforepost in the business rules pane I get
beforepost(deltachange).
Also in the documentation row is used (http://wiki.remobjects.com/wiki/Business_Rules_Scripting_Global_Object)

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

Thank you for report this issue was logged as #49042.

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

The default error message window is not skinned.

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