in the wiki it is stated Declare the function above as custom function:
DAEcmaScriptProvider1.Engine.Variables.SetVariable(‘Base64GUID’, Base64GUID);
where should I do that? in de create of the module or later?
2 can I pass parameters to the function?
I made a function GetAutoScript(args: array of variant): variant;
in the onCreate of my datacervice I declared my function
in my schema I add the business rule
function onNewRow(Row)
{
row[‘ID’] = GetAutoInc([‘tableName’, ‘Fieldname’]);
}
I get the error object expected when I add an new record
ajr65 said: 1. in the wiki it is stated Declare the function above as custom function: DAEcmaScriptProvider1.Engine.Variables.SetVariable('Base64GUID', Base64GUID); where should I do that? in de create of the module or later?
You'll need do this before using this function, of course will be better do this during creation module where is this scripting component.
ajr65 said: 2 can I pass parameters to the function?
Yes, in wiki function already has parameters -
function Base64GUID(args: array of variant): variant;
I tried that but somehow It didn’t like the way I put the parameters in.
I have 3 parameters I want to pass.
I tried ([“test1”,"test2,“test3”]) and without [] but I got errors. Is there some more documentation on scripting. I don’t know javascript at all so I am a little in the dark as how to do things
function TClientDataModule.MySum(args: array of variant):variant;
begin
Result := args[2] + ’ = ’ + FloatToStr(args[1] + args[0]);
end;
procedure TClientDataModule.DataModuleCreate(Sender: TObject);
begin
DAEcmaScriptProvider1.Engine.Variables.SetVariable(‘MySum’, MySum);
end;
Call example:
function onNewRow(row)
{
row[‘MyField’] = MySum(‘X’, 1, 1.5); //returns ‘X = 2.5’
}
Please note, that arguments are passed in inverted order.
Sorry for the inconvenience, We’ll adjust wiki information asap.
function TKGsMCCService.GetAutoIncScript(args: array of variant): variant;
var
lDADataset: IDADataset;
lConnection: IDAConnection;
lSQLText: string;
lOrderNr: string;
lAutoIncField: string;
lTableName: string;
begin
//arguments are passed in inverted order
lTableName := args[0];
lOrderNr := args[1];
lAutoIncField := args[2];
if lOrderNr = ‘’ then
lSQLText := Format('Select max(%s) from %s ', [lAutoIncField, lTableName,
lOrderNr])
else
lSQLText := Format(‘Select max(%s) from %s where %s’,
[lAutoIncField, lTableName, lOrderNr]);
Unfortunately, I couldn’t reproduce the error, but got some thoughts about your code.
At the moment of function execution row[“MDORD”] may be null, not empty string, so please try
Still no succes. in the debugger I come to TScriptControl.Run and then I go from there to the DASafeCallError
what I want is get the highest mdnr for MDORD and then add 1.
MDORD is the masterkey so has this field in onNewRow a value. If not this is not the way to go.
Does it work when called with some constant value instead of row[“MDORD”]? Could be tested with something like:
function onNewRow(row)
{
fail(GetAutoIncScript(“MDNR”, 1, “MCCDCS”));
}
Weird. Please post here your DA/Delphi/Windows/msscript.ocx versions. Also test if this simplest one works on your system:
function onNewRow(row)
{
fail(“test”);
}
that will work. That is how I started out testing it
I got 2 msscript.ocx version 1.0.7600.16385
one in C:\Windows\winsxs\x86_microsoft-windows-scripting-msscript_31bf3856ad364e35_6.1.7600.16385_none_90381958050e76f8
and one in C:\Windows\SysWOW64
I also have problems getting my server plugins on windows server to work with scripting
One general suggestion: when you meet some strange problems with platform-specific behaviour (DLL/OCX/Driver issues), use “vanilla virtual machine”. I m created virtual machine (actually, several VMs), install all needed updates and software, then make a named shapshot (dont relay on auto-protect snapshots). So, when i need to perform some testing, i m just use VM from this snapshot, installing my software and testing it! After i m done with testing, i use Rollback to Snapshot command - and my virtual machine “pure” again! Just keep your snapshot’ed VM up-to-date with latest MS patches)))