How to trigger a scheduled job for every 30 mins

JMR2
Mega Expert

Good day All,

I would like to get a notification when the Duplicate Algo administration remains switched off for more than 1 hour.

The notification should be sent to all the users having the 'Duplicate Algo Administration'.

 automatic notification after 1 hour and if the algo remains off, again a notification every 30 minutes until its switched on again.

Support team should get this notification

find_real_file.png

when ever the unchecked  the check box and then automatically trigger the notification for every 30mins up to when we click the check box again(means check box is not empty)

find_real_file.png

Please help me on above requirement. Thanks in-advance.

1 ACCEPTED SOLUTION

Hi Akash, Good morning 

Thanks for your information regarding on my task. process wise OK. But I'm tried below code. NOW it's working fine

var r=new GlideRecord('sys_properties');
r.addQuery('name','Value');

r.addQuery('name','Value');
r.addQuery('value','false');
r.query();
if(r.next())
{
var u=new GlideDateTime(r.sys_updated_on);
var t=new GlideDateTime();
var d=gs.dateDiff(u,t,false);
if(d>='01:00:00'){
var pop= gs.getProperty('sys_property name');

if (pop == 'false'){
var r=new GlideRecord('sys_user');
r.query();
if(r.next())
{
gs.log('New User');
gs.eventQueue('notify_user',r,gs.getUserID(),gs.getUserName() );
}
}
}
}

Regards,

Reddy

View solution in original post

6 REPLIES 6

The SN Nerd
Giga Sage
Giga Sage

I wouldn't do this through Scheduled Jobs. Conditional Timers are best done through Workflows.

Create a Workflow on the System Property Table.

Condition: Name = <Your property> and Value is true

  • Wait 1 hour (Timer activity)
  • IF
    • Value is still true
    • Has not been updated in the past hour
  • ELSE 
    • Stop workflow
  • Wait 30 minutes (Time activity)
  • IF
    • Value is still true
    • Has not been updated in the past 30 min
  • ELSE
    • Stop workflow
  • Send email
  • Go back to "wait 30 minutes"

Was hoping to be able to do this through flow, but you can't put a timer into a loop.

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Akash4
Kilo Sage
Kilo Sage

Hello,

If I consider your case from the initial stage, you need to do the following things:

1. Create a notification if you do not have yet! say - Notify support users and configure all required details on When Who and What

find_real_file.png

2. Create a event in Event Registry and provide this event name in the above notification step

find_real_file.png

3. Create a scheduled job and script as shown below to trigger for every 30 mins if the property is inactive

Regards, Akash

 

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

Problem with that would be that the property could be set 1 minute before that scheduled job runs, so users would be getting an email after 1 minute, not 30.

The first one also needs to be an hour.

Alas, I think workflow is the way to go. It is a bit too complex using events and scheduled jobs in my view.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

That's nice! In case the solution doesn't work and before moving to workflows, we can use GlideDate() APIs to verify the 30 min lag, what would you say?

Also, I guess as I am using an If loop to check the property once again before triggering - in the script block, hope this removes the ambiguity.

Regards, Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.