I have a map that contains three items = a feature layer of properties, a feature layer of other locations, and a table related to the latter that represents a 1:M relationship. In playing with the FeatureSet functions I can get this statement to return a featureset of records from the table, and has 115,882 records in it:
var RelRecs = FeatureSetById($datastore, "1")
But the following statements both return empty record sets:
Where are you applying the expression?
Are you able to share the full snippet?
A featureset is a lightweight collection of all your features. If you want to ensure that you are correctly calling the featureset from the map, I'd suggest using the profile variables in a map Arcade expression builder. This helps ensure you use the correct layer name. For a large dataset, you should also be only calling the field(s) you will use, to improve performance.
Where you are applying the expression is important, as not all Profiles will support the FeatureSetCollection - a colleciton of feature sets. It's only supported working with $map and $datastore profile variables, e.g. pop-up.
https://developers.arcgis.com/arcade/guide/types/#featuresetcollection
https://developers.arcgis.com/arcade/profiles/popup/
https://developers.arcgis.com/arcade/guide/profiles/
the $map profile variable represents a collection of layers (i.e. FeatureSets) in the map of the $feature used in the execution of the Arcade expression.
the $map profile variable represents a collection of layers (i.e. FeatureSets) in the map of the $feature used in the execution of the Arcade expression.
I would recommend:
Good tutorials/guides:
https://learn.arcgis.com/en/projects/access-attributes-from-another-layer-with-arcade/
For context: I am using this method to relate records from a spatial layer and a table, in this instance these are both published together in a feature service (arcgis server, not hosted). As you can see the very first line is the code line that I posted initially and indicates it works (using the count method you suggested. In this situation the FeatureSetbyID function works because these items are part of the same service. This code block essentially gets a value from a shared unique ID and uses that to filter the related table, and then other code below line 5 perform some grouping to summarize data. This code all works as does other code that comes downstream of what is shared; as you mentioned I could probably improve its performance by pulling only the fields necessary.
var RelRecs = FeatureSetById($datastore, "1")
var countRelrecs = Count(RelRecs);
Console(countRelrecs);
var FilQry = "UPCCODE = '" + $feature["UPC"] + "'";
var RelRecs_filter = Filter(RelRecs, FilQry);
var CallsByType = GroupBy(RelRecs_filter,
[
{name:'Department', expression:'BU_SOURCE'},
{name:'Type' , expression:'CALLDESCRIPTION'}
],
[
{name:'Total',expression:'1',statistic:'COUNT'},
{name:'Points',expression:'POINTVALUE',statistic:'SUM'}
I want to use the $map functions to create a similar filter based on retrieving a matching ID value from a different layer in the map. However, both the code lines return feature set with 0 records, since this is the first line of the code block, nothing that follows is relevant. The lines of code are taken directly from the profile variable so I'd think they should function properly.
The question still remains as to why the methods using the $map profile variable return 0 records while the $datastore method returns the entire feature set represented by the table. Is it simply because the table and layer aren't part of the same feature service?