How can I restrict email notifications on weekends using Groovy?

You can write a groovy script in Application Composer for your object that restricts email notifications from sending at the weekend (both Saturday and Sunday) to specified recipients.

Let's say you've scheduled a process to run daily to cater for the following condition: If a Lead isn't updated from the last 7 days, then automatically trigger an email notification for the lead owner.

To restrict the notification from being triggered on weekends, use the following sample code at the start of your script to get the day of the week and then use the condition to either run the rest of the code or skip it as follows.

def date = new Date()
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
def day = calendar.get(Calendar.DAY_OF_WEEK);
if (day == 7 || day == 1){ //1 is mapped to Sunday and 7 is mapped to Saturday
println('Do Nothing')
}
else{
//write the rest of the code that you want to run on weekdays
}
Note: Before you enable notifications for Sales, ensure that you've enabled notifications generally. For steps how to do this, see the topic, Disable or Enable Workflow Notifications. If you update your sales application, be sure to go back and check these settings again.