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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Help! How do I invoke a custom Thingworx service with a parameter by using Java Script?

Figo
1-Visitor

Help! How do I invoke a custom Thingworx service with a parameter by using Java Script?

I am developing my own experience in Thingworx studio. I just want to use Java script to invoke my custom Thingworx service with a parameter input. Thanks very much.

4 REPLIES 4
katte
12-Amethyst
(To:Figo)

If you are looking to get the data from a ThingWorx service, then it can be done as:

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

   // which invokes the service and returns the service output

And to assign the parameter value -

$scope.app.mdl['Thingname'].data.parameter['parametername'] = "input value" ;

In order to invoke service with the required input parameter, you can try assigning the parameter first and in the next step invoke the service execute step.

-Giri

Figo
1-Visitor
(To:katte)

Hi, Giri. If i use script  to set parameter like:  $scope.app.mdl['ServiceItem-1'].data.parameter['currentStep'] = 'xxxxx',  debug console will report error "TypeError: Cannot read property 'parameter' of undefined".

asiirilä
4-Participant
(To:Figo)

I am facing the same issue. What would be the reason that the thing is undefined in javascript? but when I bind a property from the very same thing directly to some widget I get the property values as expected.

asiirilä
4-Participant
(To:Figo)

Hi,

When I console.log the content of mdl object in the home.js as below:

console.log($scope.app.mdl);

I get the object nicely logged in the console

console_3.PNG

If I then copy the path to the BatteryCharge property (just under the pop-up) and try to log its value as follows:

console.log($scope.app.mdl.KCERoofBox.properties.BatteryCharge);

I'll get the following error:

console_4.PNG

So it seems that the KCERoofBox object is undefined.

What am I doing wrong?

I've also tried the following call with the same results:

console.log($scope.app.mdl['KCERoofBox'].properties['BatteryCharge']);


Please could someone help me out with this one?


Br,

Antti

Announcements

Top Tags