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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Is it possible to control an external data in JS?

yhwan
1-Visitor

Is it possible to control an external data in JS?

Hi

When I call a service on some Things (external data), I drag and drop the button widget onto a service.

I would like to call a service by writing js code.

Is it possible?

5 REPLIES 5
ankigupta
12-Amethyst
(To:yhwan)

Hi Yoo hwan​ Could you please share your use case in more detail.

yhwan
1-Visitor
(To:ankigupta)

Hi

In my project, I can control the widget's visibility by writing js code and calling it.

Like this.

When I press a toggle button, playAll function is executed.

So, I want to execute a service in external data in the same way as above.

Not drag-and-drop but calling a function in JS.

Can I do it?

katte
12-Amethyst
(To:yhwan)

By saying external data, I anticipate you must be trying to work with TWX data. Besides drag-n-drop, Thingworx Studio supports JS code. The syntax that you are using is to access Studio widget, whereas for accessing TWX service, please follow the below syntax:

$scope.app.mdl['yourthingname'].svc['yourTWXservicename']; // returns the result of a service, can be stored in a variable or accordingly

$scope.app.mdl['yourthingname'].data.current['Name']; // returns the value of a Thing

Technically, the code should be written following the syntax of AngularJS framework.

Thanks,

Giri

yhwan
1-Visitor
(To:katte)

Hi, giri

Thanks to reply.

I tried it, but I didn't see any changes.

'query' returns info table data and the data is used in drawing a chart.

Is it wrong syntax?

katte
12-Amethyst
(To:yhwan)

As the query returns infotable data, I would say the coding is incomplete. This is a bit complex for timeseries widget, as it is a manual code it is expected to manage everything in a great detail. For example, in your code the 'x-axis' and 'y-axis' fields are missing. I would also recommend to make use of watch variables for debugging or to determine the correct data is being received.

Announcements

Top Tags