Only Display Entries From Survey123 By Rolling Date Range (weekly)

597
3
Jump to solution
11-02-2023 07:15 AM
Labels (2)
GregReinecke
New Contributor III

Hello All,

Weekly I collect a respondents First and Last Name and the Date Created (hidden) for an event. The SignUp opens On Sunday and closes Thursday at noon).  Currently I clear the survey data every Saturday night and reset the Survey123 date range opening and closing for the coming week.

I really don't mind that I delete the data but also wouldn't mind keeping the data for later analysis BUT no matter what I just only want to see the current weeks data.

Currently I show the results in a table widget in Experience Builder.  Here is the survey link https://arcg.is/8T4q  and I have attached a simple .xlsx form.

I think this could be done a few ways supporting "IF an entry falls within the upcoming week THEN display it ELSE don't display it" 

  1. Arcade expression in ArcGIS to create a field that adheres to the criteria
  2. Some sort of expression in ExB
  3. A calculated field in Survey123
  4. ModelBuilder script

Any suggestions or kickstarts would be very helpful. Thanks in advance,

GR

0 Kudos
1 Solution

Accepted Solutions
GregReinecke
New Contributor III

This does what I want.

// This Arcade Expression assigns an attribute "Show" or "Hide" to a feature 
// based on the day and time it was created. Also assigns "Hide" if not created
//during the current week.

// Get the current week for comparison to previous weeks
var currentDate = Now();
var currentWeek = Week(currentDate);

// Get the day of the week the feature was created
var dayOfWeek = Weekday($feature._date_time);
var dayOfWeekString = "";
if (dayOfWeek == 0) {dayOfWeekString = "Sunday"} 
    else if (dayOfWeek == 1) {dayOfWeekString = "Monday"}
    else if (dayOfWeek == 2) {dayOfWeekString = "Tuesday"} 
    else if (dayOfWeek == 3) {dayOfWeekString = "Wednesday"} 
    else if (dayOfWeek == 4) {dayOfWeekString = "Thursday"} 
    else if (dayOfWeek == 5) {dayOfWeekString = "Friday"} 
    else  "Saturday"

// Get the time of day (_hour) the feature was created
var dateTimeField = $feature._date_time;
var _hour = Hour(dateTimeField);

// Get the time of day (_minute) the feature was created
var dateTimeField = $feature._date_time;
var _minute = Text(Minute(dateTimeField), '00');

// Create _hour_minute
var _hour_minute = _hour + _minute

// Get the week the feature was created
var _week = Week($feature._date_time)

if (dayOfWeek == 0 && _week == currentWeek) {return 'Show'}
    else if (dayOfWeek == 1 && _week == currentWeek) {return 'Show'}
    else if (dayOfWeek == 2 && _week == currentWeek) {return 'Show'}
    else if (dayOfWeek == 3 && _week == currentWeek) {return 'Show'}
    else if (dayOfWeek == 4 && _hour_minute <= 1200 && _week == currentWeek) {return 'Show'}  
    else return 'Hide'

View solution in original post

0 Kudos
3 Replies
GregReinecke
New Contributor III

I started getting some code together. I have two features, one from a previous week and one from this week.

The feature last week generates a boolean "false" which makes sense based on the signup date.

LastWeek.png

The second point has a signup date of yesterday which I would think would prove out to be "true" but it doesn't.

CurrentWeek.png

Perhaps it could be due to the way the date is formatted.  Here is the code if anyone wants a look.

var now = Now();
var timeZoneOffsetHours = -5; // Eastern Time is UTC-5

// Adjust the current date and time to Eastern Time
var easternNow = DateAdd(now, timeZoneOffsetHours, "hour");

// Get the current day of the week and hour
var dayOfWeek = Weekday(easternNow);
var currentHour = Hour(easternNow);

// Define the time range for Sunday midnight to Thursday noon
var isWithinTimeRange = (dayOfWeek == 1 && currentHour >= 0) || // Sunday midnight
                       (dayOfWeek >= 2 && dayOfWeek <= 4); // Monday to Thursday
var isBeforeNoon = (dayOfWeek < 4) || (dayOfWeek == 4 && currentHour < 12); // Before Thursday noon

// Check if the feature's "_date_time" is within the specified time range
var featureCreationDate = $feature._date_time;
var isFeatureCreatedThisWeek = DateDiff(Week(easternNow), featureCreationDate, "day") >= 0;

return isWithinTimeRange && isBeforeNoon && isFeatureCreatedThisWeek;

 

0 Kudos
GregReinecke
New Contributor III

Still searching….     Is it possible Now() and 

featureCreationDate

 actually have a different output format/structure so they always compare as false?  Thanks to all in advance. 

0 Kudos
GregReinecke
New Contributor III

This does what I want.

// This Arcade Expression assigns an attribute "Show" or "Hide" to a feature 
// based on the day and time it was created. Also assigns "Hide" if not created
//during the current week.

// Get the current week for comparison to previous weeks
var currentDate = Now();
var currentWeek = Week(currentDate);

// Get the day of the week the feature was created
var dayOfWeek = Weekday($feature._date_time);
var dayOfWeekString = "";
if (dayOfWeek == 0) {dayOfWeekString = "Sunday"} 
    else if (dayOfWeek == 1) {dayOfWeekString = "Monday"}
    else if (dayOfWeek == 2) {dayOfWeekString = "Tuesday"} 
    else if (dayOfWeek == 3) {dayOfWeekString = "Wednesday"} 
    else if (dayOfWeek == 4) {dayOfWeekString = "Thursday"} 
    else if (dayOfWeek == 5) {dayOfWeekString = "Friday"} 
    else  "Saturday"

// Get the time of day (_hour) the feature was created
var dateTimeField = $feature._date_time;
var _hour = Hour(dateTimeField);

// Get the time of day (_minute) the feature was created
var dateTimeField = $feature._date_time;
var _minute = Text(Minute(dateTimeField), '00');

// Create _hour_minute
var _hour_minute = _hour + _minute

// Get the week the feature was created
var _week = Week($feature._date_time)

if (dayOfWeek == 0 && _week == currentWeek) {return 'Show'}
    else if (dayOfWeek == 1 && _week == currentWeek) {return 'Show'}
    else if (dayOfWeek == 2 && _week == currentWeek) {return 'Show'}
    else if (dayOfWeek == 3 && _week == currentWeek) {return 'Show'}
    else if (dayOfWeek == 4 && _hour_minute <= 1200 && _week == currentWeek) {return 'Show'}  
    else return 'Hide'
0 Kudos