Skip to content

Commit 3ee846b

Browse files
authored
Create dynamic_catalog_task.js
1 parent af88ba1 commit 3ee846b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var CatalogTaskGenerator = Class.create();
2+
CatalogTaskGenerator.prototype = {
3+
initialize: function() {
4+
this.taskTable = 'sc_task';
5+
},
6+
generateTasks: function(ritmSysId, variableName) {
7+
var ritmGR = new GlideRecord('sc_req_item');
8+
if (!ritmGR.get(ritmSysId)) {
9+
gs.error('RITM not found for sys_id: ' + ritmSysId);
10+
return;
11+
}
12+
var taskType = ritmGR.variables[variableName].toString();
13+
switch (taskType) {
14+
case 'Laptop':
15+
this._createTask(ritmGR, 'Assign Laptop Asset', 'Hardware Fulfillment', 10);
16+
this._createTask(ritmGR, 'Install Core Software', 'Software Team', 20);
17+
break;
18+
case 'Desktop':
19+
this._createTask(ritmGR, 'Deploy Desktop Image', 'Infrastructure Team', 10);
20+
this._createTask(ritmGR, 'Setup Docking Station', 'Hardware Fulfillment', 20);
21+
break;
22+
case 'Mobile Phone':
23+
this._createTask(ritmGR, 'Order SIM Card', 'Telecom Team', 10);
24+
this._createTask(ritmGR, 'Configure MDM Profile', 'Mobile Support', 20);
25+
break;
26+
// add Cases as Catalog Tasks Required....
27+
default:
28+
gs.info('CatalogTaskGenerator: No specific tasks defined for ' + variableName + ' value: ' + taskType);
29+
break;
30+
}
31+
},
32+
33+
_createTask: function(ritmGR, shortDesc, assignmentGroupName, order) {
34+
var taskGR = new GlideRecord(this.taskTable);
35+
taskGR.initialize();
36+
taskGR.request_item = ritmGR.sys_id;
37+
taskGR.request = ritmGR.request;
38+
taskGR.short_description = shortDesc;
39+
taskGR.order = order;
40+
var groupGR = new GlideRecord('sys_user_group');
41+
if (groupGR.get('name', assignmentGroupName)) {
42+
taskGR.assignment_group = groupGR.sys_id;
43+
} else {
44+
gs.warn('CatalogTaskGenerator: Assignment Group not found: ' + assignmentGroupName);
45+
}
46+
47+
taskGR.insert();
48+
},
49+
50+
type: 'CatalogTaskGenerator'
51+
};

0 commit comments

Comments
 (0)