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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Getting Unit from properties using JS

Raphael08
7-Bedrock

Getting Unit from properties using JS

Hello,

 

getting a Property Value from Thingworx to Vuforia Studio using JavaScript is working fine with:

 

 $scope.app.mdl['Thingname'].properties['Propertiename']

 

BUT: Is it possibility to get any more information from one property like e.g. the “Description” or “Unit”?

 

Greetings

Raphael

1 ACCEPTED SOLUTION

Accepted Solutions

Using GetPropertyDefinitions is going to return an array, but it's a basic array rather than associative, so you'll have to iterate over the elements to find the one you want, something like this:

  var check = $scope.app.mdl["VuforiaChatThing"].svc['GetPropertyDefinitions'].data;
  for (var i=0; i < check.length; i++) {
    if (check[i].name=="Test_1") {
      $scope.view.wdg['3DLabel-11'].text = check[i].description;
    }
  }

 

View solution in original post

6 REPLIES 6

You can do this using the GetMetadataAsJSON service. This will give you a big JSON object, which basically has all the metadata for all the properties (and services and events) of your Thing. You'll have to drill down into the data structure to find the exact thing you want (e.g. "Units" defined for a specific property), but it should be in there.

 

Alternately, you could add a custom service to your Thing on the Thingworx side to return just the specific item you're looking for, e.g. GetPropertyUnits(name) to return a simple string value from metadata field, something like this:

// result: STRING
var result = me.GetMetadataAsJSON().propertyDefinitions[name].aspects.units;

Hi,

I would like to avoide creating Services within thingworx (due to different reasons)

 

BUT: There is an inbuild Service in Vuforia called "GetPropertyDefinitions"  like:

app.mdl['THINGNAME'].svc['GetPropertyDefinitions'].data.current['description']

 

Is it possible to use this Services within JavaScript like in this example?

 

$rootScope.$broadcast('app.mdl.Thingname.svc.NameOftheService', {

        "property":  prop, "message" :  $scope.view.wdg['textArea-1']['text']}

  );

 

https://community.ptc.com/t5/Vuforia-Studio/Manually-invoking-a-Thing-Service-using-Studio-JavaScript/td-p/524611

 

You can use the GetPropertyDefinitions service, but it will only give you the basic meta properties, and doesn't include things like "units". If you want to get the "units", you'll need to use GetMetadataAsJSON.

 

Using GetMetadataAsJSON is very similar to using GetPropertyDefinitions, it just includes a bit more structure and data. But it includes everything, including "units" and other conditional metadata, within a subset called "aspects". If you do the call, in the preview you can poke around with the debugging tools and see the structure of the JSON object it returns to figure out how to get to the exact piece of data you need.

Hi,

 I think the GetMetadataAsJSON is too complex for my project.

 

I managed to set / write all the needed "Units" within the Thing-Property "Description"

 ==> "Description" can be extracted using the Service "GetPropertyDefinitions" correct?

 

Can you help me a bit with the syntax, because following is not working:

 

$scope.view.wdg['3DLabel-11'].text = $scope.app.mdl['Raphael_1'].GetPropertyDefinitions['Test_1'].description;

 

Thanks

Raphael

 

Using GetPropertyDefinitions is going to return an array, but it's a basic array rather than associative, so you'll have to iterate over the elements to find the one you want, something like this:

  var check = $scope.app.mdl["VuforiaChatThing"].svc['GetPropertyDefinitions'].data;
  for (var i=0; i < check.length; i++) {
    if (check[i].name=="Test_1") {
      $scope.view.wdg['3DLabel-11'].text = check[i].description;
    }
  }

 

Perfect, 

this is Working, thank you!

Top Tags