I’m building a custom data action in Architect to filter interactions based on the day of the week. The goal is to route calls differently if they happen on a Monday.
I tried using GetDayOfWeek() first. It returns an integer. 0 for Sunday, 1 for Monday, and so on. The expression looked like this:
IF(GetDayOfWeek(CurrentDateTime) == 1, "RouteToTeamA", "RouteToTeamB")
This works fine for simple checks. But now I need to check if the call is within a specific time window relative to the start of the week. I thought DateTimeDiff might help.
The docs say DateTimeDiff takes two timestamps and a unit. I tried comparing CurrentDateTime against a fixed Monday timestamp. But Architect expressions don’t seem to like comparing dynamic dates directly in the diff function without parsing.
Is there a cleaner way to get the day index without relying on GetDayOfWeek? Or should I just stick with GetDayOfWeek and chain multiple IF statements? The performance hit on complex expressions worries me.
Also, GetDayOfWeek returns the day for the local timezone of the org. Is that consistent across all regions? I’m in US/Pacific. If the org is in London, does it shift?
Any tips on handling timezone-aware date comparisons in expressions? I don’t want to break routing when daylight saving time hits.
GetDayOfWeek is fine for static checks, but it’s brittle when you need ranges or business logic that shifts. If you’re trying to check “is this within a specific window” rather than just “is it Monday,” DateTimeDiff gets messy fast because you have to calculate the offset manually.
Here’s a cleaner way to handle day-of-week logic in Architect without wrestling with integer math. Use the DayOfWeek perty directly if you’re on a recent platform version, or stick to GetDayOfWeek but compare against a list if you need multiple days.
For the specific case of filtering interactions based on a date range relative to today, avoid DateTimeDiff for the day check. Instead, normalize the date to the start of the week and compare. But honestly, if you just need Monday routing, your initial approach is correct. The issue usually arises when people try to do DateTimeDiff(CurrentDateTime, StartOfWeek). That’s overkill.
Try this expression structure for a broader range check (e.g., Monday to Wednesday):
// Check if day is Mon(1), Tue(2), or Wed(3)
IF(
OR(
GetDayOfWeek(CurrentDateTime) == 1,
GetDayOfWeek(CurrentDateTime) == 2,
GetDayOfWeek(CurrentDateTime) == 3
),
"RouteToTeamA",
"RouteToTeamB"
)
If you need to check if a timestamp is within a specific business day window (e.g., 9 AM to 5 PM on weekdays), GetHour combined with GetDayOfWeek is more reliable than trying to diff against a rolling week start. DateTimeDiff is great for durations (seconds, minutes), not for calendar logic. Stick to the component extractors. It’s less code and easier to debug when the routing fails at 4:59 PM on a Friday.