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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

get value from rows

xiaoqw
15-Moonstone

get value from rows

datatable value.JPG

May I know how to get Value "23" based on Category "Outstanding PTPP" and pass value to another Datatable using for loop?

ACCEPTED SOLUTION

Accepted Solutions

below snippet will help you out. first get the datatableentry by key

iterate that to get value

now create infotable structure according to other datatable

set values to infotable entry and use adddatatableentry

**********************************************************************************

 

// result: INFOTABLE dataShape: ""
var result1 = me.GetDataTableEntryByKey({
key: "GMP" /* STRING */
});
var params = {
infoTableName : "InfoTable",
dataShapeName : "newOtherDS"
};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(newOtherDS)
var result2 = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);


var tableLength = result1.rows.length;
for (var x=0; x < tableLength; x++) {
var row = result1.rows[x];

var value = row.value; // NUMBER

// newOtherDS entry object
var newEntry = new Object();
newEntry.name = "new entry"; // STRING
newEntry.value = value; // NUMBER [Primary Key]
result2.AddRow(newEntry);
// id: STRING
var id = Things["otherDataTable"].AddDataTableEntry({
sourceType: undefined /* STRING */,
values: result2 /* INFOTABLE */,
location: undefined /* LOCATION */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
});

}

// communityDS entry object

 

 

View solution in original post

1 REPLY 1

below snippet will help you out. first get the datatableentry by key

iterate that to get value

now create infotable structure according to other datatable

set values to infotable entry and use adddatatableentry

**********************************************************************************

 

// result: INFOTABLE dataShape: ""
var result1 = me.GetDataTableEntryByKey({
key: "GMP" /* STRING */
});
var params = {
infoTableName : "InfoTable",
dataShapeName : "newOtherDS"
};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(newOtherDS)
var result2 = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);


var tableLength = result1.rows.length;
for (var x=0; x < tableLength; x++) {
var row = result1.rows[x];

var value = row.value; // NUMBER

// newOtherDS entry object
var newEntry = new Object();
newEntry.name = "new entry"; // STRING
newEntry.value = value; // NUMBER [Primary Key]
result2.AddRow(newEntry);
// id: STRING
var id = Things["otherDataTable"].AddDataTableEntry({
sourceType: undefined /* STRING */,
values: result2 /* INFOTABLE */,
location: undefined /* LOCATION */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
});

}

// communityDS entry object

 

 

Announcements

Top Tags