How to set an inbound working on weekdays.

Shinu_snow
Tera Contributor

Hello,

 

I have a scenario to create an inbound action with the following conditions:

  • When the instance receives an email containing "(CRITICAL)" in the email subject, and

  • "Integrated Management Log Severity: CRITICAL" in the email body,

  • Then an incident record should be created.

The tricky part is:

  • This should only happen on workdays (Monday to Friday).

  • Emails received on weekends (Saturday or Sunday) must be ignored, and no incident record should be created.

The condition and script I provided are shown below. The inbound action is working, and incidents are being created, but they are also being created on weekends. I need to prevent incidents from being created on weekends.

Shinu_snow_0-1755019310568.pngShinu_snow_1-1755019385763.png

Thanks in advance!!

5 REPLIES 5

Musab Rasheed
Tera Sage
Tera Sage

Try below code.

(function() {
  var dayOfWeek = new GlideDateTime().getDayOfWeekUTC(); // 1 = Sunday, 2 = Monday, … 7 = Saturday

  // Only process Monday (2) through Friday (6)
  if (dayOfWeek >= 2 && dayOfWeek <= 6) {
    // Create or update ticket logic
    current.short_description = email.subject;
    current.description = email.body_text;
    current.insert();
  } else {
    // Skip creating ticket
    return;
  }
})();
Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi, 

How can I check if the incident record is created on weekends? Should I wait until Saturday to send emails??

Tweak the code to include tomorrow's day to restrict creation of records, if works then code will work for weekend condition as well or else you have to wait I think.

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hii,

 

This isn’t working. I tested it on Sunday, but an incident was still created.