The tag <call> also supports execution of R and Javascript. It can execute code stored in catalogue tables or code can be embedded in the <body> tag. Catalog tables are:
- wic_dbscripts_js for Javascript code
- wic_dbscripts_r for R code
Both catlog tables can be reached via the wic menu:
Business Logic > Server JS/R codeNew in 2019.1
This capability is available in versions 2019.1
onwards. Previous releases do not support execution of R and Javascript
1 call
Executes a javascript or R script on the server. Javascripts are stored in wic_dbscripts_js
and R scripts in wic_dbscripts_r
table
<call
name='name'
code='code'
type='type'
>
<args> ?
<arg /> *
</args>
<body /> ?
</call>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Name of the function to invoke. The script must define a function with the same name as this attribute. | |||
Acode | string |
Code of the catalogued script used the retrieve the source code of the script.
Javascripts are retrieved from wic_dbscripts_js whereas R Scripts are retrieved from wic_dbscripts_r .
If this attribute is null, then a body argument must be used.
|
|||
Atype | string | Accepted values are js or r. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Eargs | Arguments passed to the function invoked | ||||
Earg | Argument | ||||
Ebody | Código javascript. Éste debe estar contenido en una función que será invocada son los argumentos informados. |
Returns | |
---|---|
Type | Description |
Resultado de la ejecución del script. Los tipos javascript son mapeados a tipos java. En particular, ls Arrays JS son mapeados java.util.List y los objetos JS són mapeados a java.util.Map. |
Example
The following xsql script calls an embedded JS script and an embedded R script.
Copy
<xsql-script name='hello_world'> <body> <set name="m_result_js"> <call type="js" name='sayHiFromJS'> <args> <arg>Earth</arg> </args> <body><![CDATA[ function sayHiFromJS(name) { return "Hello " + name + " from JS"; } ]]> </body> </call> </set> <set name="m_result_r"> <call type="r" name="sayHiFromR"> <args> <arg>Mars</arg> </args> <body><![CDATA[ sayHiFromR <- function(name) { d <- c("Hello", name, "from R") return(paste(d, collapse=" ")) } ]]> </body> </call> </set> <println> <m_result_js /> <m_result_r /> </println> </body> </xsql-script>
Hello Earth from JS
Hello Mars from R
Example
Execute a catalogued script:
Copy
<xsql-script > <body> <println> <return> <call name='fibonacci' type="js"> <args> <arg>10</arg> </args> </call> </return> </println> </body> </xsql-script>
89