Was this helpful?
ExecuteScript Method
The ExecuteScript method enables you to execute Javascript on a web page.
This method has the following syntax:
integer = Subform1.ExecuteScript(script = varchar(2000), execscriptevent = varchar(32));
This method has the following parameters.
script
Specifies the Javascript
execscriptevent
Specifies the user event to trigger after the script is executed
This method returns ER_OK if successful or ER_FAIL for failure. Descriptions of system constant values and their numeric equivalents are listed in Error Codes.
The script result will receive a 4GL call back method. The result value is a JSON-encoded string.
For example:
...
FIELD(subform1).Webpage = TRUE;
// frame.flush() is mandatory if FIELD(subform1).Url() is called during Form.initialize() block.
curframe.flush();
FIELD(subform1).url(html=htmlstring, pageloadevent = 'NAVIGATIONCOMPLETE');
...
FIELD(subform1).ExecuteScript(script='table.getData()', execscriptevent='EXECCOMPLETE');
...
on userevent 'EXECCOMPLETE' =
declare
retdata = VARCHAR(20000) not null;
result = stringobject;
enddeclare
{
    //retdata = StringObject(CurFrame.MessageObject).value;
    //CurFrame.StatusText = 'Script returns:' + retdata;
    result = StringObject(CurFrame.MessageObject);
    // The Script result is json encoding string.
    result.WriteToFile(filename = 'c:\temp\res.json');
}
Last modified date: 06/25/2024