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

Is it possible to control an external data in JS?

Newbie

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?

Tags (1)
5 REPLIES 5

Re: Is it possible to control an external data in JS?

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

Re: Is it possible to control an external data in JS?

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?

Re: Is it possible to control an external data in JS?

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

Re: Is it possible to control an external data in JS?

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?

Re: Is it possible to control an external data in JS?

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.