cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

INCLUDE A JS FILE IN THINGWORX

anassNasser
8-Gravel

INCLUDE A JS FILE IN THINGWORX

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

 

thanks in advance .

ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4
slangley
23-Emerald II
(To:anassNasser)

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

hi @Constantine 

  thank you for your response,

 

I accept that as a solution 

 

Anass

Announcements


Top Tags