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

4 REPLIES 4

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.

Hello yashkamde, 

Thanks for the response, but in this business rule we don't have any function for this can you please check and help me on this 

 

.getHourOfDay()
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';
    }

 

Swathi KS
Tera Contributor

@yashkamde  Thanks For the Response can you please check the business Rule which was sent in the the function(

.getHourOfDay()

) we are calling it was not working, can you please check and help me on this this the error i'm getting              Cannot find function getHourOfDay in object 2026-02-24 23:03:34.