5 Replies Latest reply on May 7, 2017 6:27 AM by roycla RSS
    rsurujbhan Newbie

    Manually invoking a Thing Service using Studio JavaScript

    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!

      • Re: Manually invoking a Thing Service using Studio JavaScript
        Ankit Gupta Ninja

        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.

          • Re: Manually invoking a Thing Service using Studio JavaScript
            xxie Explorer

            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.

            • Re: Manually invoking a Thing Service using Studio JavaScript
              roycla Newbie

              Hi Ankit,

               

              I notice your response saying that this script will actually invoke the service:


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

               

              I am not able to get this working though. If I bind the service invocation to a button click, my service runs fine and can get at the data in my javascript via:


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


              I really need to invoke the service via javascript; I am in a Hololens experience where 2D containers are not exposed so can't use Text widgets and value changed events for example. Is there any further documentation on invoking services via javascript out there?


              Regards

              Roy