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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Creating an InfoTable that contains one column of different InfoTable

lorenmc
1-Newbie

Creating an InfoTable that contains one column of different InfoTable

How do I create a new InfoTable that contains just one column of a different InfoTable?

I thought it would be:

// Code to create newInfoTable based on a specific DataShape

newInfoTable = oldInfoTable.ColumnName;

But that doesn't seem to work.

Thanks

9 REPLIES 9
paic
1-Newbie
(To:lorenmc)

Hi Loren,

What is the need for the nested infotable? (Infotable inside another infotable)


To do this, you go through Snippets/InfoTable/Create New InfoTable from Datashape you get:


var params = {

infoTableName : "InfoTable",

dataShapeName : "NameOfYourDataShape"

};


// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(FeedData)

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);


That is what you need to use to create your new InfoTable, the other part of course is to make sure you DataShape exists and has your Field(s) properly defined.



Hi Pai,

I'm not trying to create a nested infotable.  I have an infotable with multiple rows and columns and I need to do some parsing of Text that is in one of the columns.  I initially thought of just creating a new infotable that contains a single column from the original infotable.  But all I really need to do is access the data in the particular column and then do so row by row, which I plan to do in a for loop.  However, I'm not sure of the JavaScript syntax to access a particular column of an infotable.  It seems like most of the code Snippets perform operations on an entire row.


If I use a getRow() method, what is the syntax to then access a particular cell or column of that row?


Thanks



paic
1-Newbie
(To:lorenmc)

Hi Loren,

Depending on what you are going to do with the information, you probably will need to create an additional InfoTable to hold the resulting parsed information.

Anytime you loop through an InfoTable you indeed get the whole row.

I recommend you just use the:

for each (var entry in YourTableName.rows) {

}

So as this loops the variable entry will represent your row, and to get the values from a particular column then would become entry.NameOfTheColumn.


Hope that gets you on your way!



lorenmc
1-Newbie
(To:paic)

Hi Pai,


In an attempt to implement your suggestion I created the following code to create a single column infotable.  However, when executed I am left with an empty infotable.  I know "iresult" contains the orignal infotable with all of the appropriate data since I can uncomment the last line and see the data when I execute the service.  Any idea what I'm doing wrong?


var params = {

nodeId: "204113" /* STRING */

};


// result: INFOTABLE dataShape: "OnRampSDUData"

var iresult = me.GetData(params);


var params = {

infoTableName : "InfoTable",

dataShapeName : "SensorDataShape"

};


//CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"),dataShapeName:STRING):INFOTABLE(SensorDataShape)


var tempresult = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);


for each (var entry in iresult.rows) {

    tempresult.AddRow(entry.sduHex);

}


result = tempresult;

// restul = iresult;



paic
1-Newbie
(To:lorenmc)

If your DataShape for the new table has the column sduHex in it, that should work, but how about you do it the following way and add the row object the way we did it during training.


for each ...

var row = new object

row.sduHex = entry.sduHex;

tempresult.AddRow(row);





lorenmc
1-Newbie
(To:paic)

Ok, I gave that a try.  I now get an infotable with the appropriate amount of entries but all the entries are empty.  


If I look at row.sduHex, it contains the appropriate data.  However, when I look at a given row of tempresult using the getRow(index) it is indeed empty.


I don't know what's going on.





lorenmc
1-Newbie
(To:paic)

I re-read your last post carefully and realized that the DataShape for the new infotable did indeed have a different name than "sduHex". It was the same Base Type but had a different name.  When I changed the name it all seems to work now.  My new InfoTable has what I expect it to.

Thanks for the help!

can anyone please help no how to create infotable  within an info table, i need this to show Region in google map. To show Region/geoFence in goole map, it should have an infotable within info table, any help?



paic
1-Newbie
(To:abhishek1)

Hi!


Infotables receive their table structure from DataShapes. So to create the table inside a table, you create your first datashape, then you create yet another datashape with one of it's field definitions to be of base type InfoTable with that first DataShape as it's datashape.

We also have a Regions example in the Support/Example section.



Top Tags