Running business scripts on commands at server side

I use a lot of this kind of SQL commands at server side:

lCmd := aDataModule.Schema.NewCommand(lConnection, ‘Insert_Customers’);

Beeing Insert_Customers a command defined inside the schema.

The associated dataset in the schema has businnes rules script coded on pascal script to insert default values AfterInsert, sample:

procedure AfterInsert;
begin
field := 0;
end;

and check code on Beforepost.

There any way to apply this to this commands on server side?

Best regards

Hello,
What DA version do you use?
We don’t recommend to use pascal script in business rules script. It’s obsolete and isn’t used in new DA versions.
This article will be useful for you:
http://wiki.remobjects.com/wiki/Business_Rules_Scripting

Im using latest version and we dont stop using this if not be forced… Is a waye better than the javascript support. Why you dont recomend using it? The only reason can be because you will remove support for this. I really hope you dont think on do that.

Pascal script in schema modeler is a lot friendly to code. Examples:

It shows ALL THE FIELDS on the editor windows.
It shows a LOT MORE CLEAR events descriptions (like afterpost or beforepost)

And the better: is pascal.

Why can somebody think on removing something is working perfect? Wich are the advantages to Delphi users to migrate to JS on that scripts? I see zero advantages.

Dear Donald, the answer is simple:

Read follow on wiki:
The Spring 2011 release adds JavaScript-based Business Rules Scripting to Data Abstract for Delphi (Win32 only), replacing the old Pascal Script based scripting support (which is still available, but not cross-platform and now considered legacy).

I also think it works very well for Delphi Business Rules scripting, but hey, the big boss changes the rules from time to time …

Best regards, Cesar.

Hello,
You can use TDAPSScriptingProvider only on the client side.
On the server side you can use TDASpiderMonkeyScriptProvider, TDAEcmaScriptProvider, TDAActiveScriptProvider.
Pascal script is obsolete and haven’t been supported yet.

Cesar, i can see how this answer my question, but thanks.

Ok, then how can i use at server side that scripts?

Hello,
You wrote:

Ok, then how can i use at server side that scripts?

Please look at the followings aticles:
http://wiki.remobjects.com/wiki/Business_Rules_Scripting_Overview
http://wiki.remobjects.com/wiki/Business_Rules_Scripting

The wiki say:
“If you use Delphi, you simply need to place the TDASpiderMonkeyScriptProvider on the Data Abstract service and assign the ScriptProvider property on the service to the new component (for server scripting), or place the same class next to the data table(s) (TDAMemDataTable class) and assign the ScriptingProvider property on that component to the TDASpiderMonkeyScriptProvider (for client scripting).”

That is not that i need.
Im dont want to call a script when theres a request to a datatable.

I have code in the server, running not for a service request, and that code usa IDADatasets.
I need script by runned on that requests, not related to cliente calls, theres no cliente concept here, just pure server code.

See that sample server code, executed for server conditions, no client calls.

var
ActuaFacturas : IDASqlCommand;
begin
ActuaFacturas := ServerDataModule.Schema.NewCommand(lConexionFacturar,
‘Insert_wahtever’,
[‘IDFACTURA’,‘CODIGO’], [FacturaID, Codigo]);

Theres any way tis command use a rule script on the schema?

Best regards.

Hello,
Unfortunately, Business Rules Scripting works only with datatables.

Any chance to get this feature on a future? or very hard to implement?

Hello,
You can also work with Business Rules Scripting in commands if you use TRORemoteCommand component to call them.
If you want to use a rule script on the schema please do the following:

procedure TDataService.RunCommand;
var
  cmd:IDASQLCommand;
  aParameters: DataParameterArray;
  aParameterNames: array of String;
  aParameterValues: array of variant;
  aAllowed:Boolean;
  aCommandName:String;
begin
  aAllowed := False;
  aCommandName := 'NewCommand';
  ServiceSchema;//call SetupScriptProvider

  ScriptProvider.ValidateCommandAccess(aCommandName,aParameterNames, aParameterValues, aAllowed);
  if not aAllowed then raise EDADatasetNotAccessible.CreateFmt(err_CommandNotAccessible, [aCommandName]);

  aParameters:= DataParameterArray.Create;
  try
    cmd := Schema.NewCommand(Connection, aCommandName);
    ScriptProvider.BeforeExecuteCommand(cmd.SQL, cmd.Name, aParameters);
    cmd.Execute;
    ScriptProvider.AfterExecuteCommand(cmd.SQL, cmd.Name, aParameters, 0);
  finally
    FreeAndNil(aParameters);
  end;
end;

Im running the command on server side. Cant undesrtand how this apply to mi scenario.

Hello,
See the code which we pointed above.