Select to view content in your preferred language

Text box inside Card widget with Arcade code to count records

189
3
a month ago
Labels (1)
JoseSanchez
Frequent Contributor

Good morning,

I’m looking for a sample that demonstrates how to use Arcade to count records from a hosted feature layer, specifically when connected through Dynamic Content in a text widget. I’m trying to understand how to access the data source and its fields using Arcade.

Essentially, I want to achieve the equivalent of COUNT("OBJECTID") in Arcade.

 

 

0 Kudos
3 Replies
Ke_Xu
by Esri Regular Contributor
Esri Regular Contributor
0 Kudos
SanchezNuñez
Frequent Contributor

Good afternoon  @Ke_Xu 

I am looking for a way to implement this code from your link:

var ds = $dataSources["dataSource_id"].layer;

var distincItem = Distinct(ds, 'CNTRY_NAME'); return Count(distincItem);

 

Could you please explain to me how to add this line  "var ds = $dataSources["dataSource_id"].layer;" from the default function generated in Experience Builder;? How do I find the dataSource_Id?

function getFilteredFeatureSet(ds)
 
I do not understand how to  type this line $dataSources["dataSource_id"].layer;  in the function generated by Experience Builder.

 

// Documentation: https://arcg.is/18ejKn3

function getFilteredFeatureSet(ds) {
  var result = ds.layer;
  var queryParams = ds.queryParams;

  if (!IsEmpty(queryParams.where)) {
    result = Filter(result, queryParams.where);
  }

  if (!IsEmpty(queryParams.geometry)) {
    result = Intersects(result, queryParams.geometry);
  }

  return result;
}
Thanks
0 Kudos
SanchezNuñez
Frequent Contributor

Found it!


There's no need to declare a function—just typing the code is enough.

 

var ds = $dataSources["dataSource_3-1-dataView_1"].layer;
 var distincItem = Distinct(ds, 'OBJECTID');
return Count(distincItem);
itWorks_Screenshot 2025-11-12 134404.png