Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**Dynamic Catalog Task Generator**

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.


**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.
Original file line number Diff line number Diff line change
@@ -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'
};
Loading