From 4d934587fafdda5c369899e31158946b0f9abd95 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Sat, 18 Oct 2025 20:15:00 +0530 Subject: [PATCH 1/3] Create readme.md --- .../Scheduled Jobs/Recurring Task Automation/readme.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Server-Side Components/Scheduled Jobs/Recurring Task Automation/readme.md diff --git a/Server-Side Components/Scheduled Jobs/Recurring Task Automation/readme.md b/Server-Side Components/Scheduled Jobs/Recurring Task Automation/readme.md new file mode 100644 index 0000000000..caa82bd6e9 --- /dev/null +++ b/Server-Side Components/Scheduled Jobs/Recurring Task Automation/readme.md @@ -0,0 +1,3 @@ +The Recurring Task Automation project automates the creation of recurring tasks in ServiceNow based on a predefined schedule or trigger. This ensures routine operational tasks, maintenance jobs, or checks are executed consistently without manual intervention. + +Unlike OOB scheduled jobs for individual tasks, this solution is dynamic, flexible, and configurable per task type. From 4d9f30e73cca18a54e9c8c3a93b154509d231e9c Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Sat, 18 Oct 2025 20:15:28 +0530 Subject: [PATCH 2/3] Create scriptInclude.js --- .../scriptInclude.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Server-Side Components/Scheduled Jobs/Recurring Task Automation/scriptInclude.js diff --git a/Server-Side Components/Scheduled Jobs/Recurring Task Automation/scriptInclude.js b/Server-Side Components/Scheduled Jobs/Recurring Task Automation/scriptInclude.js new file mode 100644 index 0000000000..9febb519f8 --- /dev/null +++ b/Server-Side Components/Scheduled Jobs/Recurring Task Automation/scriptInclude.js @@ -0,0 +1,39 @@ +var RecurringTaskGenerator = Class.create(); +RecurringTaskGenerator.prototype = { + initialize: function() {}, + + generateTasks: function() { + var templateGR = new GlideRecord('u_recurring_task_template'); + templateGR.addActiveQuery(); + templateGR.query(); + + while (templateGR.next()) { + var lastRun = templateGR.last_run_date || templateGR.start_date; + var nextRun = new GlideDateTime(lastRun); + + // Calculate next run based on frequency + if (templateGR.frequency == 'daily') nextRun.addDaysUTC(1); + else if (templateGR.frequency == 'weekly') nextRun.addDaysUTC(7); + else if (templateGR.frequency == 'monthly') nextRun.addMonthsUTC(1); + + var now = new GlideDateTime(); + if (nextRun <= now) { + // Create new task from template + var newTask = new GlideRecord('task'); + newTask.initialize(); + newTask.short_description = templateGR.template_task.short_description + ' (Recurring)'; + newTask.description = templateGR.template_task.description; + newTask.assignment_group = templateGR.assignment_group; + newTask.assigned_to = templateGR.assigned_to; + newTask.parent = templateGR.template_task; // optional link + newTask.insert(); + + // Update last run date + templateGR.last_run_date = now; + templateGR.update(); + } + } + }, + + type: 'RecurringTaskGenerator' +}; From 9e8e52235e571bd78726a2b3bc8135c721112d43 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Sat, 18 Oct 2025 20:16:29 +0530 Subject: [PATCH 3/3] Create scheduled job.js Scheduled Script Execution (Scheduled Job) that runs daily. Calls the Script Include RecurringTaskGenerator.generateTasks(). Automatically generates tasks according to template frequency. --- .../Scheduled Jobs/Recurring Task Automation/scheduled job.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Server-Side Components/Scheduled Jobs/Recurring Task Automation/scheduled job.js diff --git a/Server-Side Components/Scheduled Jobs/Recurring Task Automation/scheduled job.js b/Server-Side Components/Scheduled Jobs/Recurring Task Automation/scheduled job.js new file mode 100644 index 0000000000..5846a5c07a --- /dev/null +++ b/Server-Side Components/Scheduled Jobs/Recurring Task Automation/scheduled job.js @@ -0,0 +1,2 @@ +var generator = new RecurringTaskGenerator(); +generator.generateTasks();