Skip to main content
1-Visitor
March 7, 2017
Question

Is it possible to control an external data in JS?

  • March 7, 2017
  • 1 reply
  • 2997 views

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?

1 reply

5-Regular Member
March 7, 2017

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

yhwan1-VisitorAuthor
1-Visitor
March 7, 2017

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?

5-Regular Member
March 7, 2017

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