KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Passing data to a Javascript function in the Web Area using 4D Object
PRODUCT: 4D | VERSION: 14.0 | PLATFORM: Mac & Win
Published On: May 5, 2014

Data in 4D can be passed through a Javascript function in a Web Area using WA EXECUTE JAVASCRIPT FUNCTION. Prior to v14, the command allowed multiple parameters of Text type for example:

$JavaScriptFunction:="TheFunctionToBeExecuted"
$Param1:="10"
$Param2:="true"
$Param3:="1000.25"

WA EXECUTE JAVASCRIPT FUNCTION(MyWArea;$JavaScriptFunction;$Result;$Param1;$Param2;$Param3)


The Javascript function would have to be programmed according to the number of parameters passed. This would be difficult to maintain if more parameters would be needed in the future. But, in v14, using 4D Object reduces the hassle of using multiple parameters with WA EXECUTE JAVASCRIPT FUNCTION. The parameters can be coupled into one single object.

C_OBJECT($Params)

OB SET($Params;"Param1";"10")
OB SET($Params;"Param2";"true")
OB SET($Params;"Param3";"1000.25")

WA EXECUTE JAVASCRIPT FUNCTION(MyWArea;$JavaScriptFunction;$Result;$Params)


The 4D object is passed in as a JSON notation where a Javascript function can accept. If more data would need to be packed in a 4D object, it can be easily added for the future.