Skip to main content
1-Visitor
August 7, 2019
Solved

Getting Unit from properties using JS

  • August 7, 2019
  • 1 reply
  • 4040 views

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

Best answer by ClayHelberg

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;
 }
 }

 

1 reply

18-Opal
August 8, 2019

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;
Raphael081-VisitorAuthor
1-Visitor
August 9, 2019

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

 

18-Opal
August 9, 2019

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.