Select to view content in your preferred language

Using an Array in the for loop of an Arcade Expression

1861
3
06-18-2020 06:15 PM
DonSjoboen
Occasional Contributor

Hello Xander Bakker

I'm trying (unsuccessfully) to use an Array in my for loop to return the unique route (along with other columns) that is in a related customer table.  See example below...

The top table is my customers table (i.e. related table), and the bottom table is my point feature class.  The related fields are "CO_ID = CONNECTION_OBJECT".

Below is my Arcade expression...

var tbl = FeatureSetByPortalItem(Portal('https://organization.com/'), 'ItemID', 1);
Console(Count(tbl));
var id = $feature["CO_ID"];
Console(id);
var sql = "CONNECTION_OBJECT = '" + id + "'";
Console(sql);
var customers = Filter(tbl, sql);
var myArray = customers;
var cnt = Count(customers);
Console(cnt);
var result = "";
if (cnt > 0) {
for (var k in myArray) {
/* var ROUTE = myArray[0];
console(ROUTE);
result += TextFormatting.NewLine + "Routes: " + ROUTE +
*/ result += TextFormatting.NewLine + k;
}

} else {
result = "No customer data"
}

Console(result);
return result;

What happens is that I get the right ID and count of related records, but I keep getting the last record (in my customers table) repeating 4 times, with the same route "R003N".  What I am trying to get is something that looks like this for the popup...

Address: 123 Main St

Customer: John Doe

Business Partner Number: 111111111

Contract Account: 222222222

Routes:

F0001 / [CommSup] / M

FC01 / [CommSup] / F

GL01 / [CommSup] / M

R003 / [CommSup] / M

Thanks in advance for your help!  Let me know if you have any questions or need further clarification.

Don

0 Kudos
3 Replies
XanderBakker
Esri Esteemed Contributor

HiDon Sjoboen ,

Quick question; is the field CONNECTION_OBJECT numeric or string? If it is numeric you should omit the quotes around the ID when you construct the SQL.

0 Kudos
DonSjoboen
Occasional Contributor

Hello Xander Bakker,

The field [CONNECTION_OBJECT] is an integer.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Don Sjoboen ,

Did you try changing the "sql" like this?

var tbl = FeatureSetByPortalItem(Portal('https://organization.com/'), 'ItemID', 1);
Console(Count(tbl));
var id = $feature["CO_ID"];
Console(id);
var sql = "CONNECTION_OBJECT = " + id;
Console(sql);
var customers = Filter(tbl, sql);
var myArray = customers;
var cnt = Count(customers);
Console(cnt);

var result = "";
if (cnt > 0) {
    for (var k in myArray) {
    /* var ROUTE = myArray[0];
    console(ROUTE);
    result += TextFormatting.NewLine + "Routes: " + ROUTE +*/ 
    result += TextFormatting.NewLine + k;
    }
} else {
    result = "No customer data"
}

Console(result);
return result;
0 Kudos