Skip to main content
1-Visitor
December 13, 2018
Solved

Adding multiple 'category' to properties, services and events

  • December 13, 2018
  • 7 replies
  • 3820 views

Hello,

Is it possible to add/set multiple category to same property or service? When we define a property in a Thing, there is a provision also to add a Category (which is helpful in organising and searching), so I would like to know if I can put a property/service in multiple category? If yes, then how?

To better understand what I mean please refer the attached screen shot. So in the screen shot I have 2 properties, property t1 has (better to say, I tried to put) category as POLLED, PLOTTABLE while t2 has category as POLLED. What I would want is when I call the service (generic service) 'GetPropertyDefinitions' with category parameter as POLLED, I should get both t1 and t2 (right now I am only getting t2) and when I call the same service with category parameter as PLOTTABLE, I should get only t1 (right now I am getting nothing).

Please suggest if that's possible.

Thanks in advance

Regards

Aditya Mittal

Best answer by amittal-3

Hello @mneumann,

I got what I was looking for. I should say it was very nearby, but I couldn't just see it 🙂

The way to get/read the category of a property is:

me.GetNamedProperties({propertyNames:{"items":["myProp1"]}}).dataShape.fields["myProp1"].category;

Thanks for your support.

Regards

Aditya

7 replies

16-Pearl
December 13, 2018

Hi,

the Category seems to be based on a STRING variable.

http://support.ptc.com/help/thingworx_hc/thingworx_8_hc/en/#page/ThingWorx%2FHelp%2FComposer%2FThings%2FThingProperties%2FProgrammaticallyAddingPropertiestoThings.html

 

I don't think that it will split it into arrays - but it will just consider it as a whole.

It might be an option to write a custom service, which is based on the GetPropertyDefinitons (get back all of them) and then split the Category and filter for the split values.

 

Cheers,

Michael

amittal-31-VisitorAuthor
1-Visitor
December 14, 2018

Hi Michael,

Thanks for your reply. Continuing on your suggestion do you know how can I read the category of a Property? I mean when I checked, I think I found that 'category' field does not belong to aspects. For your reference I am attaching the Property definition from XML, and there since I didn't find category as aspects.category unlike other fields such as 'aspect.isLogged' or 'aspect.isPersistent' so I am thinking that maybe I cannot read category using aspects. I am not sure if my assumption is correct or not.

 

<PropertyDefinition aspect.cacheTime="0.0" aspect.dataChangeType="VALUE" aspect.isLogged="false" aspect.isPersistent="false" aspect.isReadOnly="false" baseType="STRING" category="POLLED PLOTTABLE" description="" isLocalOnly="false" name="t1" ordinal="1"/>

Thanks

Aditya

16-Pearl
December 17, 2018

Hi @amittal-3

you would need this service output and pass it to another service which is then using the

https://www.w3schools.com/jsref/jsref_split.asp split() Method on the category.

With this result you can operate on the category array - e.g. to check or return individual categories.

 

The output of the new custom service can then be used instead of the original GetPropertyDefinitons.

 

Cheers,

Michael