Hello,
I am looking for a way to use Arcade in Dashboards to return the day of the year from a date field.
Due to the lack of Globals in Arcade for Dashboards, I have first called the FeatureSet using FeatureSetByPortalItem.
var p = 'https://www.arcgis.com'
var itemId = '998628deb4b144e8a17afd9ab606d700' // note this is an example ID from a different service
var fs = FeatureSetByPortalItem(Portal(p), itemId, 0, ['*'], false)
I am then looking for a way to use either the ISOWeek or Text functions (Text(date, DDD) to return the week or day from a date field within the FeatureSet. So far I've been unsuccessful in finding a way to pull out the date field (called RecordDate_rep) from the FeatureSet to then call the week/day functions mentioned above. I presume I'm missing something obvious, but any help is appreciated.
I was then attempting something like this, but it doesn't work, returning "Execution Error:Runtime Error: Cannot call member property on object of this type.":
var dat = fs.RecordDate; // extract Date field from FeatureSet
var day = Text(dat, 'DDD'); // Format date as day of year
return day; // output day of year
@XanderBakker if you are able to assist on this I would greatly appreciate it.
Solved! Go to Solution.
If you use the data from the itemID in your message, it works correctly
var p = 'https://www.arcgis.com'
var itemId = '998628deb4b144e8a17afd9ab606d700';
var fs = FeatureSetByPortalItem(Portal(p), itemId, 1, ['*'], false) //layerId 0 doesn't have a date field
var feature = First(fs);
var theDate = feature.LastMaintenance;
var theDay = Text(theDate, 'DDD');
return `${theDay} (${Text(theDate,'MMM D, YYYY')})`;
//returns 47 (Feb 16, 2021)
If you use the data from the itemID in your message, it works correctly
var p = 'https://www.arcgis.com'
var itemId = '998628deb4b144e8a17afd9ab606d700';
var fs = FeatureSetByPortalItem(Portal(p), itemId, 1, ['*'], false) //layerId 0 doesn't have a date field
var feature = First(fs);
var theDate = feature.LastMaintenance;
var theDay = Text(theDate, 'DDD');
return `${theDay} (${Text(theDate,'MMM D, YYYY')})`;
//returns 47 (Feb 16, 2021)
Thank you for your help on this. Testing the code you provided shows this works with my data too. However in Dashboards, when I click Done, it shows thee is an issue with the Data expression and doesn't let me use it for the Serial Chart. Hovering on the warning symbol shows the warning: "Unable to execute Arcade script"
I'm assuming I need to return a FeatureSet rather than a value. Do I need to create a data schema (as suggested in this thread: https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-data-expression-quot-unab...)? In my case, I will need to return the number of records per unique day of the year.
Yes, create a dictionary from the result and return it like in the example @XanderBakker provides.
Thanks, I managed to get it working, but by week instead of day.