Hi Ameer,
In order to execute JavaScript, your engine needs to have that capability. So I am assuming you might want to toggle the script for the purpose of script implementations and not so much for the script support of the product.
Do use the JSON to control that, you could for instance create a JSON file like this on a path like Resources/Configuration/scripttype.json:
{
"functionKeysLoad" : true,
"optionsSelect": false
}
And create a structure to contain these values in LegaSuite/Seagull script, in my example I've names the structure Scripts/ScriptType.structure:
Structure ScriptTypeStruct
dim functionKeysLoad as integer
dim optionsSelect as integer
End Structure
This file can be read into a global variable, that can be used in both LegaSuite script as well as JavaScript.
Reading by JavaScript can be done for instance like this:
/* import the file system api for file handling */
import * as fs from 'mx:fs';
// Just a small example to read configuration data to a global variable
let fullpath = script.environment.pckgdir + 'Resources/Configuration/scripttype.json';
let file_contents = fs.readTextFile(fullpath);
let imported_persons = JSON.parse(file_contents);
script.global.gScriptType = new script.structure.ScriptTypeStruct(JSON.parse(file_contents));
console.log("script.global.gScriptType.functionKeysLoad=" + script.global.gScriptType.functionKeysLoad + ", script.global.gScriptType.optionsSelect=" + script.global.gScriptType.optionsSelect);
And in LegaSuite script for instance using something like this:
Option Explicit
Global gScriptType as ScriptTypeStruct
Dim filecontents as string
Dim filename as string
Dim result as integer
filename = @"@&&WRKDIR@" + "/Resources/Configuration/scripttype.json"
result = FileLoad(filename, filecontents, -3)
If (result > 0) then
' flags:
' 0 (default) This flag specifies that any JSON valueis encoded. Note that this method is discourage as it may not be possibleto interact with other JSON systems.
' 1 - Forces the script to fail. When the flag is notspecified, the script goes on and any errors are indicated via the global variable ERR.
' 2 - Reserved.
' 4 - Ignore Missing Data. This flag specifies thatstructure members are filled even when not all values are specifiedin the JSON string.
' 8 - Convert types. This flag specifies that all non-matchingvalue types are converted.
' 32 - Initialize script variable before filling itwith values from JSON string / xml. (default not set)
result = ReadJSON(gScriptType, filecontents, 1 + 4 + 8 + 32)
'return values:
'0 - No error.
'1 - Parsing error.
'2 - Invalid JSON String.
'3 - Invalid variable.
'4 - Type mismatch.
'5 - No data in JSON string matching structure member 'member_name'.
if ((result = 0)) then
MessageBox("Success", "Script type for functionKeysLoad=" + str(gScriptType.functionKeysLoad) + ", script type for optionsSelect=" + str(gScriptType.optionsSelect), 0, 0)
else
MessageBox("Error", "Something went wrong", 1, 0)
end if
end if
To decide which script to run, you would need to add both JavaScript and LegaSuite script to your object events, and in the scripts decide.
For instance in a LegaSuite script:
If gScriptType.functionKeysLoad = 0 then
<... do the work ...>
End If
And similar for the JavaScript:
if (script.global.gScriptType.functionKeysLoad) {
<... do the work ...>
}
This approach would cause duplicate definitions for every event and every script in the two types though.
Hope this helps,
Regards,
Roger.