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

Accessing state Information from State Definition

  • June 13, 2018
  • 4 replies
  • 2169 views

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

Best answer by CarlesColl

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 🙂

 

4 replies

22-Sapphire I
June 13, 2018

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-31-VisitorAuthor
1-Visitor
June 14, 2018

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

1-Visitor
June 14, 2018

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 🙂