
I have created a sequence function on the app start up to enable me to load a date range This works fine and the date range loads with the correct format in a drop down field, however I need it to default to the current week and not the past week or in my case the week 2 weeks prior based on the selection in the sequence.
Is there a way I can add to the sequence that will ensure on load it defaults to the current week and then allows the user to select a previous week from the drop down if required.
I should add this is part of a timesheet app. Sequence code is
Concurrent(
Set(
CurrentUser,
User()
),
Set(
ConcurrentMonday,
DateAdd(
Today(),
-1 * (Weekday(
Today(),
Monday
) -1),
Days
)
),
Set(
weekList,
ForAll(
Sequence(
10,
Day(
DateAdd(
Today(),
-1 * (Weekday(
Today(),
Monday
) - 1),
Days
)
) - 14,
7
),
Date(
Year(Today()),
Month(Today()),
Value
)
)
)
);
Ignore the current user section at the very top of the info above. its the section from the Set highlighted in red that set's my date range,
In addition I also have the following set on the drop down field on the screen that populates this data, in the 'Items' section of the field setting.
AddColumns(
weekList,
"WeekEnd",
DateAdd(
Value,
6,
Days
),
"Week Display",
Value & " to " & DateAdd(
Value,
6,
Days
)
)
You can see from the screenshot the date range defaults to 2 weeks prior not this week, e.g. 03.01.2022 - 09.01.2022 etc.
Thanks in advance
I think I figured it out for you. I wasn't able to do it at all originally due to the way Add columns transforms the data source.
In the initial sequence change the name of the variable you are using for your sequence to something like tempWeekList.
Then add this:
ClearCollect(weekList,
AddColumns(
tempWeekList,
"Week Display", Value & " to " & DateAdd(Value,6,Days)
))
Set your ComboBox Items property to 'weekList' and select the Week Display field.
Set your DefaultSelectedItems to: (This finds the Monday of the current week and uses it for comparison)
[LookUp(weekList, Value = DateAdd(Today(),1-Weekday(Today(),StartOfWeek.Monday),Days)).'Week Display']