Arcade: How do I use a variable as the field list parameter for FeatureSetById?

1324
2
Jump to solution
10-25-2019 09:45 AM
RobBlash
Occasional Contributor III

I'm trying to pass a variable for the fieldList parameter of the FeatureSetById function. See line 13. 

If I remove [relFSAtts] from line 13 and return all fields, my script works fine. But when I use a variable in an attempt to retrieve only some fields, no featureset is returned.

My console output looks correct, so I'm not sure why it's not working

'ParentTapNumber', 'CustomerName', 'CustomerContact'

Any ideas on how to make this work? I want to avoid hard-coding attributes where possible, because this is a script I'll use frequently.

//Set the name of the related table, foreign key field, and attributes to include in the feature set
var relTable = "MyTableName_5212"
var relKey = "ParentTapNumber"
var relAtts = "'CustomerName', 'CustomerContact'"
var relFSAtts = "'" + relKey + "', " + relAtts
console(relFSAtts)

// Get feature attributes from parent table and build query to get related records
var featID = $feature.TapNumber;
var featQry = relKey + " = '" + featID + "'";

// Get feature set from related table based on ID in map, and filter it with the query
var fSet = FeatureSetById($map,reltable,[relFSAtts]);
var fSetFilt = Filter(fSet, featQry);

//Declare placeholder variables for each attribute, and declare utility variables
var CustomerNameResult;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi Rob Blash  and PKlingman-esristaff ,

You will need to provide an Array (list) of fields. You can do this like this, if you really want to do it...

//Set the name of the related table, foreign key field, and attributes to include in the feature set
var relTable = "MyTableName_5212"
var relKey = "ParentTapNumber"
var relAtts = "CustomerName,CustomerContact"
var relFSAtts = Split(Concatenate([relKey, relAtts], ","), ",");

Resulting in:

["ParentTapNumber","CustomerName","CustomerContact"]

View solution in original post

2 Replies
by Anonymous User
Not applicable

Hi Rob,

I think I figured out the reason this was failing as well as a solution - see the sample/explanation here:

/* The issue was that we needed to set variables so the array 
FieldList variable returns:
"STATE_ABBR","POPULATION"
var returnFields = "'STATE_ABBR', 'POPULATION'" returns as 
"'STATE_ABBR', 'POPULATION'" within the array, even though it returns
as 'STATE_ABBR', 'POPULATION' in the console*/

//set variables
var fieldList1 = "STATE_ABBR"
var fieldList2 = "POPULATION"
var returnFields = "'STATE_ABBR', 'POPULATION'"

//FeatureSetByID examples
var fSet0 = FeatureSetById($map, "USA_States_Generalized_5897", [fieldList1, fieldList2])
var fset1 = FeatureSetByID($map, "USA_States_Generalized_5897", [returnFields])
var fset2 = FeatureSetByID($map, "USA_States_Generalized_5897", ['STATE_ABBR', 'POPULATION'])

//console logging
console ([fieldList1, fieldList2])
console (returnFields)
console ([returnFields])
console (['STATE_ABBR','POPULATION'])

return fSet0‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Console:

["STATE_ABBR","POPULATION"] 
'STATE_ABBR', 'POPULATION' 
["'STATE_ABBR', 'POPULATION'"] 
["STATE_ABBR","POPULATION"]

Results:

 

Hope this helps,

-Peter

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Rob Blash  and PKlingman-esristaff ,

You will need to provide an Array (list) of fields. You can do this like this, if you really want to do it...

//Set the name of the related table, foreign key field, and attributes to include in the feature set
var relTable = "MyTableName_5212"
var relKey = "ParentTapNumber"
var relAtts = "CustomerName,CustomerContact"
var relFSAtts = Split(Concatenate([relKey, relAtts], ","), ",");

Resulting in:

["ParentTapNumber","CustomerName","CustomerContact"]