Select to view content in your preferred language

Use Arcade to Filter FeatureSet by Current Date

84
2
Thursday
Labels (1)
CameronLacelle
Frequent Contributor

I have two datasets that I am joining where one is the primary dataset of features with geometry and the other is stemmed from a Survey123 form that contains entries for active restrictions to the primary dataset (parking related for our municipal airport).

I use the FeatureSetByPortalItem function in Arcade to pull in all features for the primary feature and the survey feature. I want to use the Filter function to filter the survey feature to only retain active restrictions based on the rest_start and rest_end date fields that indicate when the restriction is to begin and end. I know that in the Filter function you use SQL syntax to apply the filter you want but I can't seem to get mine to work. What am I doing wrong here? See below a snippet of the code used to pull in the feature set and the end of the filter function where I try to apply the SQL query. It seems to throw an error related to the GETDATE().

-------------------------------------

var p = '<OUR AGOL URL>'
 
var restrictions = Filter(FeatureSetByPortalItem(Portal(p), '<ITEM ID>', 0, ['aircraftparkingnames','rest_type','rest_type_other','rest_name','rest_start','rest_end','rest_desc'], false), 'rest_start <= GETDATE() AND rest_end > GETDATE()')
0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

I'd swap out GETDATE() for Now()

var p = '<OUR AGOL URL>';

var restrictions = Filter(
    FeatureSetByPortalItem(
        Portal(p),
        '<ITEM ID>',
        0,
        ['aircraftparkingnames', 'rest_type', 'rest_type_other', 'rest_name', 'rest_start', 'rest_end', 'rest_desc'],
        false
    ),
    'rest_start <= Now() AND rest_end > Now()'
);
CameronLacelle
Frequent Contributor

Thanks, I've used Now() for other things in arcade (if statements and such) but since I've read the filter function uses SQL syntax I thought I had to use GETDATE().

 

Appreciate the response 🙂

0 Kudos