Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
I want to develop something in js and call it from a service in thing, can anyone have an idea ?
thanks in advance .
Solved! Go to Solution.
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
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
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.
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