Select to view content in your preferred language

Dashboard Data Expressions: What Has Changed (June 2023)

4997
3
06-15-2023 06:39 AM
Labels (1)
DavidNyenhuis1
Esri Contributor
8 3 4,997

With this past release of Arcade, the FeatureSet() function now accepts dictionaries. You may be familiar with writing the following on the last line of your data expression.

return FeatureSet(Text(dict))

This was because the FeatureSet() function only accepted JSON as text as an input. Now you can update this to...

return FeatureSet(dict)

Why is this important, you might ask. For one, it offers a performance gain. Secondly, it addresses an issue that many of you have asked to fix: Allow Date() values in date fields (esriFieldTypeDate)

When you create a feature set using the old technique, the Text() function converts Arcade dates to an ISO8601 string. However, the FeatureSet() constructor from JSON text needs an EPOCH value. So, in the past you had to wrap your dates with a Number() function (e.g., Number(Now())) before you constructed your feature set. And, if you didn’t, you’d end up with what looked like a zero-row feature set returned.

DavidNyenhuis1_0-1686682183114.png

Now that FeatureSet() accepts dictionaries, dates don’t have to be cast to EPOCH. For example, the following will now execute and return a valid feature set.

var dict = {
  fields: [{ name: "DateField", type: "esriFieldTypeDate" }],
  features: [{ attributes: { DateField: Now() } }],
  geometryType: ""
};

return FeatureSet(dict);

DavidNyenhuis1_3-1686683307113.png

That’s a wrap. Keep creating amazing dashboards.

Note for Enterprise users: This update is targeted for the 11.2 release. For previous versions you will have to utilize a technique of wrapping your dates in Number() to convert them to EPOCH and wrap your dictionary in Text() (e.g., FeatureSet(Text(myDict)) ). See this post for more detail.

3 Comments
JohannesLindner
MVP Alum

YES! Thus ends my personal crusade against that particular irksome problem. Now to make working with Featuresets more performant 🙂

@jcarlson , your workaround from these excellent blogs is finally no longer necessary...

 

DavidNyenhuis1
Esri Contributor

As a note, you can also pull the schema from a feature set and avoid typing out all the field definitions. This can be done using the Schema() function to get the schema, which includes an array of fields and the geometry type.

 

// Get a feature set by portal item (need to define parameters)
var fs1 = FeatureSetByPortalItem(p, itemID, layerID, fields, false);

// Get the schema from the feature set
var fs1Schema = Schema(fs1);
var fs1Fields = fs1Schema.fields;
var fs1GeomType = fs1Schema.geometryType;

//Create empty dictionary with the same schema
var dict = {
    'fields': fs1Fields,
    'geometryType': fs1GeomType,
    'features': []
};

// After adding features, return it as a feature set
return FeatureSet(dict);

 

MeleKoneya1
Regular Contributor

@DavidNyenhuis1  I have two FeatureSets that I am trying to join in a dictionary.   The two Featuresets share the same schema.   How do I loop the features and add them to the dictionary once the schema is set?    Thank you