Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hi,
The logic:
Infotable A has 2 columns.
Delete column 1 in infotable A.
Now the infotable has only 1 column.
Read each row of infotable A and compare with a string.
If there is a match, add some strings to infotable B.
Return infotable B.
I get no syntax errors, but my script returns infotable B with no data when I have a matching string in the if statement condition.
***********code*********************************************************
var params = {
infoTableName: "visibleOrgUnitInfoTable" /* STRING */
};
// result: INFOTABLE
var result = Resources["InfoTableFunctions"].CreateInfoTable(params);
//Add a new field to the InfoTable:
result.AddField({name: "visibleOrgUnits", baseType: "STRING"});
// result: INFOTABLE dataShape: EntityList
var currentUserOrgUnits = Resources["CurrentSessionInfo"].GetCurrentUserOrganizationalUnits();
currentUserOrgUnits.RemoveField('description');
for each (var rowThing in currentUserOrgUnits.row) {
if(rowThing.currentUserOrgUnits == "ABCOrg:ABCOrgUnit") {
// add data rows
result.AddRow({visibleOrgUnits : "ABC Org Unit A"});
result.AddRow({visibleOrgUnits : "ABC Org Unit B"});
result.AddRow({visibleOrgUnits : "ABC Org Unit C"});
result.AddRow({visibleOrgUnits : "ABC Org Unit D"});
result.AddRow({visibleOrgUnits : "ABC Org Unit E"});
result.AddRow({visibleOrgUnits : "ABC Org Unit F"});
result.AddRow({visibleOrgUnits : "ABC Org Unit G"});
}
}
Solved! Go to Solution.
I only know an old school way but this below at least returned some expected result.
var params = { infoTableName: "visibleOrgUnitInfoTable" /* STRING */ }; // result: INFOTABLE var result = Resources["InfoTableFunctions"].CreateInfoTable(params); //Add a new field to the InfoTable: result.AddField({name: "visibleOrgUnits", baseType: "STRING"}); // result: INFOTABLE dataShape: EntityList var currentUserOrgUnits = Resources["CurrentSessionInfo"].GetCurrentUserOrganizationalUnits(); currentUserOrgUnits.RemoveField('description'); var mytablesize = currentUserOrgUnits.length; for(i=0;i<mytablesize;i++){ // changed the matching string to "Everyone:Everyone" to test on my ThingWorx if(currentUserOrgUnits[i].name == "Everyone:Everyone") { // add data rows result.AddRow({visibleOrgUnits : "ABC Org Unit A"}); result.AddRow({visibleOrgUnits : "ABC Org Unit B"}); result.AddRow({visibleOrgUnits : "ABC Org Unit C"}); result.AddRow({visibleOrgUnits : "ABC Org Unit D"}); result.AddRow({visibleOrgUnits : "ABC Org Unit E"}); result.AddRow({visibleOrgUnits : "ABC Org Unit F"}); result.AddRow({visibleOrgUnits : "ABC Org Unit G"}); }
I only know an old school way but this below at least returned some expected result.
var params = { infoTableName: "visibleOrgUnitInfoTable" /* STRING */ }; // result: INFOTABLE var result = Resources["InfoTableFunctions"].CreateInfoTable(params); //Add a new field to the InfoTable: result.AddField({name: "visibleOrgUnits", baseType: "STRING"}); // result: INFOTABLE dataShape: EntityList var currentUserOrgUnits = Resources["CurrentSessionInfo"].GetCurrentUserOrganizationalUnits(); currentUserOrgUnits.RemoveField('description'); var mytablesize = currentUserOrgUnits.length; for(i=0;i<mytablesize;i++){ // changed the matching string to "Everyone:Everyone" to test on my ThingWorx if(currentUserOrgUnits[i].name == "Everyone:Everyone") { // add data rows result.AddRow({visibleOrgUnits : "ABC Org Unit A"}); result.AddRow({visibleOrgUnits : "ABC Org Unit B"}); result.AddRow({visibleOrgUnits : "ABC Org Unit C"}); result.AddRow({visibleOrgUnits : "ABC Org Unit D"}); result.AddRow({visibleOrgUnits : "ABC Org Unit E"}); result.AddRow({visibleOrgUnits : "ABC Org Unit F"}); result.AddRow({visibleOrgUnits : "ABC Org Unit G"}); }
The problem with the original posted code it's that's accessing an unknown column: rowThing.currentUserOrgUnits
it should be: rowThing.name
I tried that before I posted here but it didn't work.
This is what I got from Chrome after running the service.
The code is very intuitive! Thank you! It works!