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

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

Function does not return infotable with strings that were added

Willie
16-Pearl

Function does not return infotable with strings that were added

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"});
}
}

1 ACCEPTED SOLUTION

Accepted Solutions
tkawasaki
15-Moonstone
(To:Willie)

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"});
}

View solution in original post

4 REPLIES 4
tkawasaki
15-Moonstone
(To:Willie)

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.

 

 

Capture.PNG

The code is very intuitive!  Thank you!  It works!  

Top Tags