From 3ee846bd6a6a82624614de138d73de9b83558c71 Mon Sep 17 00:00:00 2001 From: MANCHALA YASWANTH <71426465+MYaswanth28@users.noreply.github.com> Date: Wed, 15 Oct 2025 22:05:26 +0530 Subject: [PATCH 1/3] Create dynamic_catalog_task.js --- .../dynamic_catalog_task.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Server-Side Components/Server Side/Dynamic Catalog Task Creation/dynamic_catalog_task.js diff --git a/Server-Side Components/Server Side/Dynamic Catalog Task Creation/dynamic_catalog_task.js b/Server-Side Components/Server Side/Dynamic Catalog Task Creation/dynamic_catalog_task.js new file mode 100644 index 0000000000..ddc4ddc305 --- /dev/null +++ b/Server-Side Components/Server Side/Dynamic Catalog Task Creation/dynamic_catalog_task.js @@ -0,0 +1,51 @@ +var CatalogTaskGenerator = Class.create(); +CatalogTaskGenerator.prototype = { + initialize: function() { + this.taskTable = 'sc_task'; + }, + generateTasks: function(ritmSysId, variableName) { + var ritmGR = new GlideRecord('sc_req_item'); + if (!ritmGR.get(ritmSysId)) { + gs.error('RITM not found for sys_id: ' + ritmSysId); + return; + } + var taskType = ritmGR.variables[variableName].toString(); + switch (taskType) { + case 'Laptop': + this._createTask(ritmGR, 'Assign Laptop Asset', 'Hardware Fulfillment', 10); + this._createTask(ritmGR, 'Install Core Software', 'Software Team', 20); + break; + case 'Desktop': + this._createTask(ritmGR, 'Deploy Desktop Image', 'Infrastructure Team', 10); + this._createTask(ritmGR, 'Setup Docking Station', 'Hardware Fulfillment', 20); + break; + case 'Mobile Phone': + this._createTask(ritmGR, 'Order SIM Card', 'Telecom Team', 10); + this._createTask(ritmGR, 'Configure MDM Profile', 'Mobile Support', 20); + break; + // add Cases as Catalog Tasks Required.... + default: + gs.info('CatalogTaskGenerator: No specific tasks defined for ' + variableName + ' value: ' + taskType); + break; + } + }, + + _createTask: function(ritmGR, shortDesc, assignmentGroupName, order) { + var taskGR = new GlideRecord(this.taskTable); + taskGR.initialize(); + taskGR.request_item = ritmGR.sys_id; + taskGR.request = ritmGR.request; + taskGR.short_description = shortDesc; + taskGR.order = order; + var groupGR = new GlideRecord('sys_user_group'); + if (groupGR.get('name', assignmentGroupName)) { + taskGR.assignment_group = groupGR.sys_id; + } else { + gs.warn('CatalogTaskGenerator: Assignment Group not found: ' + assignmentGroupName); + } + + taskGR.insert(); + }, + + type: 'CatalogTaskGenerator' +}; From b9f4bacc2fee5cdb33f55a19e165598c51bba025 Mon Sep 17 00:00:00 2001 From: MANCHALA YASWANTH <71426465+MYaswanth28@users.noreply.github.com> Date: Wed, 15 Oct 2025 22:08:33 +0530 Subject: [PATCH 2/3] Create README.md --- .../Dynamic Catalog Task Creation/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Server-Side Components/Server Side/Dynamic Catalog Task Creation/README.md diff --git a/Server-Side Components/Server Side/Dynamic Catalog Task Creation/README.md b/Server-Side Components/Server Side/Dynamic Catalog Task Creation/README.md new file mode 100644 index 0000000000..b8003eb5bc --- /dev/null +++ b/Server-Side Components/Server Side/Dynamic Catalog Task Creation/README.md @@ -0,0 +1,14 @@ +**Dynamic Catalog Task Generator** + +This Script Include(Attached.js File) provides a flexible, maintainable way to create one or more Service Catalog Tasks (sc_task) on a Request Item (sc_req_item). Instead of relying on complex, branching logic within a single Workflow or Flow, this script determines which tasks to create based on the value selected by the user in a single variable on the catalog form. + +This is a best practice for managing Service Catalogs because it: + +**Centralizes Task Logic**: Keeps all task definitions (short descriptions, assignment groups, order) in one easy-to-read script. + +**Improves Maintainability**: You only update this single script when task requirements change, not a sprawling visual flow. + +**Increases Flow Reusability**: The core Flow/Workflow remains simple, focused only on calling this generator. + +**Usage** +This script is intended to be called from a Run Script action within a Flow Designer Flow From 0787b43f1c396249cfe860dc6f027613fbf3298d Mon Sep 17 00:00:00 2001 From: MANCHALA YASWANTH <71426465+MYaswanth28@users.noreply.github.com> Date: Thu, 16 Oct 2025 22:12:44 +0530 Subject: [PATCH 3/3] Update README.md --- .../Server Side/Dynamic Catalog Task Creation/README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Server-Side Components/Server Side/Dynamic Catalog Task Creation/README.md b/Server-Side Components/Server Side/Dynamic Catalog Task Creation/README.md index b8003eb5bc..4f01439860 100644 --- a/Server-Side Components/Server Side/Dynamic Catalog Task Creation/README.md +++ b/Server-Side Components/Server Side/Dynamic Catalog Task Creation/README.md @@ -1,14 +1,10 @@ **Dynamic Catalog Task Generator** -This Script Include(Attached.js File) provides a flexible, maintainable way to create one or more Service Catalog Tasks (sc_task) on a Request Item (sc_req_item). Instead of relying on complex, branching logic within a single Workflow or Flow, this script determines which tasks to create based on the value selected by the user in a single variable on the catalog form. +This Script Include provides a flexible, maintainable way to create one or more Service Catalog Tasks (sc_task) on a Request Item (sc_req_item). Instead of relying on complex, branching logic within a single Workflow or Flow, this script determines which tasks to create based on the value selected by the user in a single variable on the catalog form. -This is a best practice for managing Service Catalogs because it: **Centralizes Task Logic**: Keeps all task definitions (short descriptions, assignment groups, order) in one easy-to-read script. **Improves Maintainability**: You only update this single script when task requirements change, not a sprawling visual flow. **Increases Flow Reusability**: The core Flow/Workflow remains simple, focused only on calling this generator. - -**Usage** -This script is intended to be called from a Run Script action within a Flow Designer Flow