Create a scheduled job
Create a job that runs a server-side script on a cron schedule, such as a daily reminder on incidents that have not been updated.
Create a scheduled job when a server-side script must run on a timetable, such as every night. Administrators use jobs for housekeeping and reminders that no user action triggers.
Before you begin
- You need the
administratorrole. - Write and test the script first, for example in Administration → Administrator tools → Server script.
- Decide how often the job runs. Avoid every minute, so the job does not add needless load.
- If the job must reach other instances, create it while a change set is active.
Steps
-
Go to Administration → Configuration → Jobs and select New.
-
In Job name, enter a name that says what the job does. A prefix such as
(CUSTOM)keeps your jobs apart from shipped ones. -
In Cron expression, enter the schedule, such as
0 0 1 ? * * *for 01:00 every day. Select the asterisk (*) icon next to the field to build the expression in a dialog instead. -
In Description, say what the job does and why.
-
In Script, enter the server-side script. The example below adds a reminder to open incidents that nobody has updated for 14 days.
-
Select Active and save.
let numberOfDaysCutoff = 14; // could be read from an application property instead
let cutOffDateTime = DateTime().minusDays(numberOfDaysCutoff).toStartOfDay();
Table("Incident")
.AND(
LTE("UpdatedOn", cutOffDateTime),
EQUAL("Closed", false),
NOT(EQUAL("WorkflowStatus", "resolved"))
)
.forEach(function (_incRec) {
_incRec.WorkJournal("This " + _incRec.getTableName() + " is open but has not been updated for "
+ numberOfDaysCutoff.toString() + " days. Please review to see if it can be progressed or resolved.");
// Uncomment the next line to save the journal entry on the incident
// _incRec.update();
});
Result
The job runs at each time the cron expression gives, in the instance time zone. To stop it, clear Active. Only active jobs are scheduled, so a job you save inactive never runs.