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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

[Help] Get field values dynamically from InfoTable

tallrain
10-Marble

[Help] Get field values dynamically from InfoTable

Hi there!

I'm writing a service to convert any InfoTable to CSV text.

The input is InfoTable without DataShape, it can be any InfoTable, with any filed definition.

Now to make this service possible, I need to read data from InfoTable rows dynamically.

Normally, I can use row.FieldName to get field value.

But in my case, the feild name is a variable, so I want to use some function like row.values[myVariable].

And I cannot find any possible method to read data as I expected.

Any advise?

Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
tallrain
10-Marble
(To:CRArko)

Thanks for the information, but I cannot access into that article.

 

And I've fixed this issue with below codes :):

---------------------------------------------------------------------------------------------------------

var iLF;
var tmp = 'TIME';
var i = 0;
var fd = []; // array to store Fields
fd[0] = 'TIME';

// Get CSV Header
if ((myInfoTable.dataShape===null)||(myInfoTable.dataShape===undefined)) {
iLF = myInfoTable.ToJSON().dataShape.fieldDefinitions;
} else {
iLF = myInfoTable.dataShape.fields;
}
for (var key in iLF) {
if(key != 'TIME') {
i = i + 1;
fd[i] = key; // Store field sequence
tmp = tmp + ',' + key;
}
//var result = key;
//Logger.info("Field Name "+key+" baseType: "+iLF[key].baseType);
}
tmp = tmp + ' \n';
//logger.info('JSON2CSV, i='+i);

// Get CSV Data
var tableLength = myInfoTable.rows.length;
for (var x=0; x < tableLength; x++) {
var row = myInfoTable.rows[x];
//logger.info('JSON2CSV, row='+row);
tmp = tmp + dateFormatISO(row.TIME); // Get TIME Value

var fd2 = []; // To output data in sequence
for (var property in row) {
tmp2 = property; //row property
//logger.info('JSON2CSV, tmp2='+tmp2);
tmp3 = row[property]; //row value
//logger.info('JSON2CSV, tmp3='+tmp3);
var j = fd.indexOf(tmp2);
fd2[j] = tmp3;
}

for (var k=1; k<fd2.length; k++) {
tmp = tmp + ',' + fd2[k];
}
tmp = tmp + ' \n';
}

var result = tmp;

---------------------------------------------------------------------------------------------------------

View solution in original post

3 REPLIES 3
CRArko
17-Peridot
(To:tallrain)

Hello.

 

Would some of the examples offered in this article about Dynamic Queries get you started in the right direction? Let me know if this is helpful.

 

-- Craig A.

tallrain
10-Marble
(To:CRArko)

Thanks for the information, but I cannot access into that article.

 

And I've fixed this issue with below codes :):

---------------------------------------------------------------------------------------------------------

var iLF;
var tmp = 'TIME';
var i = 0;
var fd = []; // array to store Fields
fd[0] = 'TIME';

// Get CSV Header
if ((myInfoTable.dataShape===null)||(myInfoTable.dataShape===undefined)) {
iLF = myInfoTable.ToJSON().dataShape.fieldDefinitions;
} else {
iLF = myInfoTable.dataShape.fields;
}
for (var key in iLF) {
if(key != 'TIME') {
i = i + 1;
fd[i] = key; // Store field sequence
tmp = tmp + ',' + key;
}
//var result = key;
//Logger.info("Field Name "+key+" baseType: "+iLF[key].baseType);
}
tmp = tmp + ' \n';
//logger.info('JSON2CSV, i='+i);

// Get CSV Data
var tableLength = myInfoTable.rows.length;
for (var x=0; x < tableLength; x++) {
var row = myInfoTable.rows[x];
//logger.info('JSON2CSV, row='+row);
tmp = tmp + dateFormatISO(row.TIME); // Get TIME Value

var fd2 = []; // To output data in sequence
for (var property in row) {
tmp2 = property; //row property
//logger.info('JSON2CSV, tmp2='+tmp2);
tmp3 = row[property]; //row value
//logger.info('JSON2CSV, tmp3='+tmp3);
var j = fd.indexOf(tmp2);
fd2[j] = tmp3;
}

for (var k=1; k<fd2.length; k++) {
tmp = tmp + ',' + fd2[k];
}
tmp = tmp + ' \n';
}

var result = tmp;

---------------------------------------------------------------------------------------------------------

I use this service to convert InfoTable into CSV, so that I can display data into Dygraph widget.

And for Dygraph, the 1st field is always Datatime, so this Service put field of TIME for Time Sequence.

Now it works just fine.

Top Tags