Skip to main content
Nov 12, 2020 2:45 AM UTC
Question

How to call Java from JavasScript service ?

Hi,

The engine that's used by ThingWorx JavaScript service is Rhino, it supports calling java directly as following : 

seanccc_0-1605149043198.png

. However , the similar usage doesn't work in ThingWorx JavaScript Service : 

seanccc_1-1605149103738.png

 

How to make it work in JavaScript service ? 

 

Regards,

Sean

4 replies

Nov 12, 2020 10:05 AM UTC


Hello @seanccc,

 

Have you tried using with output string :

 

var pi = Math.PI;

result = Math.PI;

 

 

 

Hope it helps,

seancccAuthor
Nov 13, 2020 8:26 AM UTC

@Ciprian-Traian ,

 

Thank, you .  var pi = Math.PI;  works,  but I got the same error when doing further testing : 

 
 
 
 

============Rhino debugger=============

rhino native.png

 

 

============ThingWorx============

rhino interface.png

 

Regards,

Sean

Nov 13, 2020 12:01 PM UTC

Java primitive and classes are not exposed in ThingWorx Script Services.

 

You can create Java entities and services using the ThingWorx Extension SDK.

Tutorial : https://developer.thingworx.com/resources/guides/eclipse-plugin-thingworx-extension-development-tutorial

 

Regards.

seancccAuthor
Nov 13, 2020 3:30 PM UTC

@smainente ,

 

Do you know the reason why the java primitive classes are not exposed ?   it  bring lots of convenience for development.   

 

Regards,

Sean