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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

How to code extracting column value from infotable row when columns/fields are dynamic

khayes1
13-Aquamarine

How to code extracting column value from infotable row when columns/fields are dynamic

Hi,

is there a way to extract a value from an infotable row based on the column index. Normally you extract the data by referencing the field name

i.e.  var myVal = myInfotable.rows[x].fieldname ;

 

However, I am using GetLoggedProperties() service to create a list of property names. I then iterate through this list and use the QueryNamedPropertyHistory service to create the table using an enrty from  list of logged property names as an input.

Ideally I'd like to be able to extract the data values from the resultant infotable using something like:

var row = myInfotable.rows[x] ;

var myVal = row.Fields['xxxxxx'] ; (where 'xxxxx' is the input property name)

 

Is there a simple way to do this? I do know that because I only pass in 1 property name that the column I'm interested in will be the second one, so perhaps I could use an index?

 

Thanks,

K

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
khayes1
13-Aquamarine
(To:PaiChung)

Hi,

I don't think that will work as although I know the name of the property it is only known as a string

e.g.

myArray = ["prop1", "prop2", "prop3"] ;

 

for(x=0; x< myArray.length ; x++)

{

      var propName = myArray[x] ;

      var propValueTable = QueryNamedPropertyHistory(propName) ;  // I know this syntax is wrong 

 

      for(y=0; y< propValueTable.rows.length ; y++)      

      {

           var row = propValueTable.rows[y] ;

           // now here's my problem

           var rowVal = row.propName ; //This bit won't work will it?

      }

}

View solution in original post

5 REPLIES 5
PaiChung
22-Sapphire I
(To:khayes1)

Are you saying that you don't actually know what the field name is?

Since you are querying on a specific Property, you would know the field name and can  reference directly that way.

Here btw is a snippet that might help as well:

// infotable datashape iteration
var dataShapeFields = yourInfotableHere.dataShape.fields;
for (var fieldName in dataShapeFields) {
//logger.warn('field name is ' + dataShapeFields[fieldName].name);
//logger.warn('field basetype is ' + dataShapeFields[fieldName].baseType);
}

khayes1
13-Aquamarine
(To:PaiChung)

Hi,

thanks for replying.

yes I do know the property name just not sure of the syntax of the code to use to extract the row value. For example if I knew the property name was 'Temperature' what would the code look like to retrieve the row value?

 

Essentially I have 2 for loops, one within the other. The outer loop iterates through a list of property names which are used individually as the input to the QueryNamedPropertyhistory service. The inner loop then iterates through the infotable result of the Query service. This is where I'm struggling, what does the code look like to get the returned values from each row. Can I use something like:

var val =  yourInfotableHere.dataShape.fields['inputPropertyName'] ;

 

Thanks in advance

K

 

PaiChung
22-Sapphire I
(To:khayes1)

you can just use rowObject.NameOfColumn to get the value.

so:

for each (var row in myInfotable.rows) {

var valueIwant = row.ColumnIWant

}

khayes1
13-Aquamarine
(To:PaiChung)

Hi,

I don't think that will work as although I know the name of the property it is only known as a string

e.g.

myArray = ["prop1", "prop2", "prop3"] ;

 

for(x=0; x< myArray.length ; x++)

{

      var propName = myArray[x] ;

      var propValueTable = QueryNamedPropertyHistory(propName) ;  // I know this syntax is wrong 

 

      for(y=0; y< propValueTable.rows.length ; y++)      

      {

           var row = propValueTable.rows[y] ;

           // now here's my problem

           var rowVal = row.propName ; //This bit won't work will it?

      }

}

PaiChung
22-Sapphire I
(To:khayes1)

Yep that should work

Top Tags