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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Accessing state Information from State Definition

amittal-3
13-Aquamarine

Accessing state Information from State Definition

Hello,

Is there a way to get/access the state information from state definition, in a Thing's service? I would like to get how many states are present in a particular State Definition, and what are their values?

Thanks in Advance

Aditya Mittal

1 ACCEPTED SOLUTION

Accepted Solutions

There isn't an snippet to do that, but you may use the technique I've pointed out to recover style information:

 

 

var data = StateDefinitions["State_Test"].GetDifferencesAsJSON({otherEntity: "StatusState"});
var result =data.rows[data.rows.length-1].difference.rows[0].oldValue.value;

This returns a String which it's exactly what you want.

 

Enjoy :)

 

View solution in original post

4 REPLIES 4
PaiChung
22-Sapphire I
(To:amittal-3)

Are you wondering about the Thingworx State Definitions?

You should be able to get that info from /<server>:<port>/Thingworx/StateDefinitions/NameOfYourStateDefinition

Not sure if there is an actual service native to a state definition that can give you that.

 

I'm a little thrown off since you mention the word Thing.

amittal-3
13-Aquamarine
(To:PaiChung)

Hello,

Thanks for your reply. I was actually referring to Thing only. What I needed was if there is a way to get the details of State Information from State Definition (just repeating what I wrote above :-)).

Suppose I have a State Definition named "State_Test", so I meant if there is some service like

StateDefinition["State_Test"].GetStateInformation();  //just an example (maybe returns Infotable)

I mean just like we access the property or information about any other entity in Thingworx. I could not find any standard service or any other way to access the metadata (like aspects in case of Thing Entities) of State Definition.

Although there is one service, which gives some information about state Definition Entities, but not entirely what I need

StateDefinition["State_Test"].GetMetadata();  //returns Infotable

I want to have state Information which includes fields like 

"stateDefinitions" : [ {
    "defaultStyleDefinition" : "",
    "defaultValue" : "0",
    "description" : "",
    "displayString" : "",
    "name" : ""
  }]

So if there is a way to get this info, please let me know.

Thanks

Aditya

There isn't an snippet to do that, but you may use the technique I've pointed out to recover style information:

 

 

var data = StateDefinitions["State_Test"].GetDifferencesAsJSON({otherEntity: "StatusState"});
var result =data.rows[data.rows.length-1].difference.rows[0].oldValue.value;

This returns a String which it's exactly what you want.

 

Enjoy :)

 

amittal-3
13-Aquamarine
(To:CarlesColl)

Thanks once again...:-)

Top Tags