Need Help on Business Rule creation- check the details below

Swathi KS
Tera Contributor

We need to create a Business Rule on the Email [sys_email] table in ServiceNow.

At the time of record insertion, the rule should check whether the email is created between 9:00 AM and 6:00 PM IST.

If the condition is met, the Type field should be updated to Send Ignored.

After i need Scheduled job should run after 6pm ist and updated the above emails to send Ready state

2 REPLIES 2

GlideFather
Tera Patron

Hi @Swathi KS ,

 

it looks that you have gathered all the requirements, where's the problem? What did you do and where did you get stuck?

_____
100 % GlideFather experience and 0 % generative AI

yashkamde
Kilo Sage

Hello @Swathi KS  ,

 

According to you requirements the BR should be :

var now = new GlideDateTime();
    now.addSeconds(19800); // IST offset = +5:30 = 19800 seconds (In case your TZ is different)

    var hour = parseInt(now.getHourOfDay(), 10);
    if (hour >= 9 && hour < 18) {
        current.type = 'send-ignored';
    }

 

and for Scheduled Job :

var gr = new GlideRecord('sys_email');
    gr.addQuery('type', 'send-ignored');
    gr.query();

    while (gr.next()) {
        gr.type = 'send-ready';
        gr.update();
    }

//Note run Daily at 6 PM 

 

If my response helped mark as helpful and accept the solution.