Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
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?
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?
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
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?
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.