Select to view content in your preferred language

Some date-based Arcade expressions not executing after last week's ArcGIS Online update

685
3
10-31-2023 05:21 PM
acarmody
Regular Contributor

Several arcade expressions used in Dashboards have stopped working.

Getting the error: "Test execution error: Unknown error. Verify test data."

Had no problems before the update, anyone else having this issue? Could the new date functions (DateOnly etc.) be the cause?

Appreciate if anyone can help.

Below is of my expressions that have stopped working:

 

var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '[feature layer id]' , 0, ['CreationDate','WeightKg'], false);

var DateDict = {'fields': [{ 'name': 'Date', 'type': 'esriFieldTypeDate'},
                        {'name': 'Weight', 'type': 'esriFieldTypeDouble'}],
                    'geometryType': '', 'features': []};

// start variable for unix calculation
var start = ToLocal(Date(1970, 0, 01, 0, 0, 0, 0))


// variable for today, used to filtered averages < today
var t = DateDiff(Date(Year(today()),Month(today()),Day(today()),0,0,0,0),start, 'milliseconds')
 

for (var f in fs){
    var new_f = {'attributes':{'Date':DateDiff(
                                                Date(Year(f['CreationDate']),
                                                Month(f['CreationDate']),
                                                Day(f['CreationDate']),
                                                0,
                                                0,
                                                0,
                                                0)
                                                ,start, 'milliseconds'),
                                                'Weight':f['WeightKg']}}
                                                Push(DateDict.features, new_f)}


var fs_gb = GroupBy(featureset(text(DateDict)), "Date", { name: 'TodayWeightSum', expression: 'Weight', statistic: 'SUM' });
console(t)
return filter(fs_gb, 'Date = @t')

 

 

3 Replies
ArmstKP
Frequent Contributor

@acarmody We are having the same issue, FYI.

0 Kudos
timcneil
Esri Contributor

Hello acarmody, 

Sorry to hear you're experiencing issues.

Date is a reserved keyword in SQL and should not be used as a field name. However, that isn't what is causing this to fail. 

The problem is that `t` in your script is a number (indicating the number of milliseconds) which cannot be used to filter by a date. You should convert the value in milliseconds to a Date first, and then you can filter based on that date value. 

The following script below should work. Notice that after t is calculated in milliseconds, it is converted to a Date, before being used in the Filter expression. 

 

var fs = FeatureSetByPortalItem(

  Portal("https://www.arcgis.com"),

  "[feature_layer_id]",

  0,

  ["CreationDate", "WeightKg"],

  false

);

var DateDict = {'fields': [{ 'name': 'Date', 'type': 'esriFieldTypeDate'},

                        {'name': 'Weight', 'type': 'esriFieldTypeDouble'}],

                    'geometryType': '', 'features': []};




// start variable for unix calculation

var start = ToLocal(Date(1970, 0, 01, 0, 0, 0, 0))







// variable for today, used to filtered averages < today

var t = DateDiff(Date(Year(today()),Month(today()),Day(today()),0,0,0,0),start, 'milliseconds')

t = Date(t)

console(t)




for (var f in fs){

    var new_f = {'attributes':{'Date':DateDiff(

                                                Date(Year(f['CreationDate']),

                                                Month(f['CreationDate']),

                                                Day(f['CreationDate']),

                                                0,

                                                0,

                                                0,

                                                0)

                                                ,start, 'milliseconds'),

                                                'Weight':f['WeightKg']}}

                                                Push(DateDict.features, new_f)}

var fs_gb = GroupBy(featureset(text(DateDict)), "Date", { name: 'TodayWeightSum', expression: 'Weight', statistic: 'SUM' });

console(count(fs_gb))

console(t);

var g = filter(fs_gb, "Date = @t")

for(var mm in g) {

return mm.TodayWeightSum

}




return "No results"

 

Thanks, 

Taylor

0 Kudos
acarmody
Regular Contributor

Hi Taylor,

Thanks for taking a look - I've tried your script and unfortuntely it is still not working.

I don't necessarily need the date returned as a date, I am just returning the summed weight value and displaying it in an dashboard indicator. 

What I don't understand is, our script was working for the last year, and only after the AGOL update there are issues with it. Are you able to provide any advice? Should @ArmstKP and I submit support tickets?

 

0 Kudos