Skip to main content
1-Visitor
March 2, 2020
Solved

INCLUDE A JS FILE IN THINGWORX

  • March 2, 2020
  • 1 reply
  • 2069 views

I want to develop something in js and call it from a service in thing, can anyone have an idea ?

 

thanks in advance .

Best answer by Constantine

Hello @anassNasser,

 

In ThingWorx you can't import dependencies directly from files, because all code is in the database, so you need to wrap it into ThingWorx entities first.

 

For example, instead of this:

import { calculator } from "my-calculator-module";
var sum = calculator.add(1, 2);

you can do something like that:

var calculator = Things["MyCalculatorModule"];
var sum = calculator.add({ x: 1, y: 2 });

 

Regards,
Constantine

1 reply

Community Manager
March 3, 2020

Hi @anassNasser.

 

Your question is not clear, but here are a couple of resources that may help:

 

Creating, Implementing and Testing Services

Building ThingWorx Applications Using Reusable Components

 

If you still have questions after reviewing these, please let us know.

 

Regards.

 

--Sharon

1-Visitor
March 4, 2020

thank you @Sharon

 

 

my question is about using javaScript in a external file and import it in a service in thingworx , like in python we use , import file as fl inside a service or in another file. 

18-Opal
March 4, 2020

Hello @anassNasser,

 

In ThingWorx you can't import dependencies directly from files, because all code is in the database, so you need to wrap it into ThingWorx entities first.

 

For example, instead of this:

import { calculator } from "my-calculator-module";
var sum = calculator.add(1, 2);

you can do something like that:

var calculator = Things["MyCalculatorModule"];
var sum = calculator.add({ x: 1, y: 2 });

 

Regards,
Constantine