4D v14.3

WA Evaluate JavaScript

Home

 
4D v14.3
WA Evaluate JavaScript

WA Evaluate JavaScript 


 

WA Evaluate JavaScript ( {* ;} object ; jsCode {; type} ) -> Function result 
Parameter Type   Description
Operator in If specified, object is an object name (string) If omitted, object is a variable
object  Form object in Object name (if * is specified) or Variable (if * is omitted)
jsCode  String in JavaScript code
type  Longint in Type into which to convert result
Function result  Date, Object, Pointer, Real, Text, Time in Result of evaluation

The WA Evaluate JavaScript command executes, in the Web area designated by the * and object parameters, the JavaScript code passed in jsCode and returns the result.

By default, the command returns values as strings. You can use the optional type parameter to specify typing for the value returned. To do this, pass one of the following constants, found in the "Field and Variable Types" theme:

Constant Type Value
Is Boolean Longint 6
Is date Longint 4
Is integer Longint 8
Is integer 64 bits Longint 25
Is JSON null Longint 255
Is LongInt Longint 9
Is object Longint 38
Is real Longint 1
Is string var Longint 24
Is text Longint 2
Is time Longint 11
Object array Longint 39

Important: Handling complex type results (objects, dates, etc.) is only possible if the Web area uses the integrated Web Kit as the rendering engine.

This example of JavaScript code causes the previous URL to be displayed:

 $result:=WA Execute JavaScript(MyWArea;"history.back()")

This example shows a few evaluations with conversion of the values received.

JavaScript functions placed in an HTML file:

<!DOCTYPE html>
<html>
    <head>
        <script>
        function evalLong(){
            return 123;
        }
        function evalText(){
            return "456";
        }
        function evalObject(){
            return {a:1,b:"hello world"};
        }
        function evalDate(){
            return new Date();
        }
    </script>
    </head>
    <body>
        TEST PAGE
    </body>
</html>

In the 4D form method, you write:

 If(Form event=On Load)
    WA OPEN URL(*;"Web Area";"C:\\myDatabase\\index.html")
 End if

You can then evaluate the JavaScript code from 4D:

 $Eval1:=WA Evaluate JavaScript(*;"Web Area";"evalLong()";Is LongInt))
  //$Eval1 = 123
  //$Eval1 = "123" if type is omitted
 $Eval2:=WA Evaluate JavaScript(*;"Web Area";"evalText()";Is string var)
  //$Eval2 = "456"
 $Eval3:=WA Evaluate JavaScript(*;"Web Area";"evalObject()";Is object)
  //$Eval3 = {"a":1,"b":"hello world"}
 $Eval4:=WA Evaluate JavaScript(*;"Web Area";"evalDate()";Is date)
  // $Eval4 = 06/21/13
  // $Eval4 = "2013-06-21T14:45:09.694Z" if type is omitted

 
PROPERTIES 

Product: 4D
Theme: Web Area
Number: 1029

Windows specific

 
HISTORY 

New
Created: 4D v11 SQL Release 2
Modified: 4D v14
Renamed: 4D v14

 
SEE ALSO 

WA EXECUTE JAVASCRIPT FUNCTION

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)

Inherited from : WA Execute JavaScript ( 4D v11 SQL Release 6)