Scheduled Trigger Based on Day of Month

Options

In order to schedule a trigger based on a weekday's placement in a month (ex/ first Monday and third Monday of the month), is the best route to use a trigger running every weekday and then have a field formula running initially to identify whether it's the first or third Monday of the month? if true, continue in the process. If false, end the process run.

I'm not seeing flexibility on the scheduled trigger itself to specify the day of the week (just keying off the start date and then calculating the recurring date from there based on defined frequency).

Let me know if anyone has a better way to accomplish this. Thanks in advance!

Tagged:

Best Answer

  • Meghan_550057
    Meghan_550057 Posts: 107
    edited February 2020 Answer ✓
    Options

    @Chris_401431 helped me with a field formula for this. The below can be used with the Field: Field Formulas action. Remove any lines starting with //. The formula will return "true" if the current day is the first or third Monday of the month, and "false" otherwise.

    var date = new Date();
    // new Date() returns the current date
    var dayOfWeekNum = date.getDay();
    var dayNumber = date.getDate();
    result = false;
    // getDay() returns integers for days of the week. Monday corresponds to "1"
    if (dayOfWeekNum === 1) {
    // we know it's Monday, now to figure out if it's the first or third Monday
    if (dayNumber < 8 || (dayNumber >= 15 && dayNumber < 22)) {
    result = true;
    }
    }
    

    From there, add a step for Pushbot: End this Pushbot with a condition for if the result is 'false' (not the first or third Monday of the month). Add conditions on the next step to start if the result is 'true' (first or third Monday of the month).

Answers