Job API
A Job is a server side script that runs on a schedule (e.g. every day, every week, etc). Out of box examples include:
Name | Period | Purpose |
|---|---|---|
Incident - Autoclosure for resolved incidents | Every day | Auto closes Resolved Incidents that had been resolved for more than pre-configured number of days (defined in application property “incident.auto_closure.days“) |
ITSM Request - Autoclosure for completed requests | Every day | Auto closes Resolved Requests that had been completed for more than pre-configured number of days (defined in application property “itsm_request.auto_closure.days“) |
Knowledge - Auto archive knowledge | Every hour | Auto archives a Knowledge article that is published but with an auto archive date set |
Creating a Job
Navigate to Administration > Configuration > Jobs and click “New” on the list of Jobs.
The following are the fields that need to be set for every Job configuration record. We have also included examples on the right most column:
Field name | Field type | Description | Example value |
|---|---|---|---|
Job name | String | Name of the job | (CUSTOM) Write internal notes as a reminder for Ageing Incidents |
Active | Boolean | If active, the Job will run at the specified interval. Set to No if you no longer want a Job record to run. | Yes |
Cron expression |
| How often and when you want the Job to run. Click on the asteriks ( * ) icon to the right of the field, to open a pop-up that will let you choose when the Job should run.
Open image-20240809-042727.png
Open image-20240809-044502.png
| Every day, at 1:00 AM
Please double check what you put in here. Avoid selecting “Every minute” in the “Minutes” tab, so no unnecessary load is placed onto your Servicely environments. |
Description | Text | Description of the job | Runs everyday to find any Incident that are open and hasn’t been updated for more than 14 calendar days, write into the Work journal to remind the assignment group/assignee |
Script | Script | The server side script you want to run when the Job is executed | // Below is an EXAMPLE and it will update Incidents that are open and hasn’t been updated for more than 14 calendar days, write into the Work journal to remind the assignment group/assigneelet numberOfDaysCutoff = 14; // can be placed into an Application property insteadlet 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."); // if uncommented, below line will update the Incident record //_incRec.update(); }); |