Skip to main content
3-Newcomer
April 18, 2017
Question

Manually invoking a Thing Service using Studio JavaScript

  • April 18, 2017
  • 1 reply
  • 7827 views

Hi Team!  In a Studio AR project, using scope commands at the AngularJS level, is there a way to manually execute a Service defined on a Thing?  Use case is having certain properties and/or input parameters change during an AR experience, and you need to re-run the Service and fetch new external data.

For example, I know you can manually play the current 3D sequence of a model widget by doing something like this:

angular.element(document.getElementById('model-1')).scope().play();

... which works fine. I also have seen examples on how to get data from a Thing Service using code like

var result = $scope.app.mdl['ThingName'].svc['servicename'] ;

...but I’m looking for a way to invoke and execute the service manually in code.  Aside from using the “Invoke On Entity Change” (doesn't seem to work in my scenario) and “Auto-refresh” configuration options that are available on Services (after adding the External Data entity in Studio), can you manually execute a Service using JS run-time commands?

Thanks!

1 reply

5-Regular Member
April 20, 2017

Robert Surujbhan​,

I am not sure if I understand your query completely.

var result = $scope.app.mdl['ThingName'].svc['servicename'] ; is actually invoking the 'servicename' service of 'ThingName' Thing.


If you are looking for how to invoke the service on parameter change. You can write this code in the function where you are changing the parameter.


If you have just done the bindings and there is no option to write code; you can use Text input widget. Bind your parameter to the Text property of Text Input widget. Uncheck the visible property to hide it at the run time. And on Value changed event of the Text input widget call the function which invokes the service.


Note: I had found some issue with Parameters not updating regularly. So, if that's the case for you; use the text property of Text Input widget directly.


I hope it helps.

1-Visitor
April 20, 2017

Hi Ankit,

I want to upload data in service, like the greenStatus.

So I write codes like this.

  1. var a = $scope.app.mdl['LEDs'].svc['GetRedStatus'].data.params['greenStatus'];

Is that right? It couldn`t run successfully.

Thanks.