4D v16.3

WA Evaluate JavaScript

Home

 
4D v16.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 longint Longint 9
Is object Longint 38
Is real Longint 1
Is text Longint 2
Is time Longint 11

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

 $result:=WA Evaluate 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 text)
  //$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



See also 

WA EXECUTE JAVASCRIPT FUNCTION

 
PROPERTIES 

Product: 4D
Theme: Web Area
Number: 1029

This command has platform-specific behavior

 
HISTORY 

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

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)