Skip to content

Commit 80252a8

Browse files
authored
Create post-script.js
Created folder and added post-script file to the folder
1 parent 59ddb1e commit 80252a8

File tree

1 file changed

+60
-0
lines changed
  • Server-Side Components/Scheduled Jobs/Scheduled Data Import for Groups Population(Support and Managed By) for CMDB Classes

1 file changed

+60
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
var impGR = new GlideRecord(data_source.import_set_table_name);
2+
impGR.addQuery('sys_import_set', import_set.sys_id);
3+
impGR.query();
4+
5+
while (impGR.next()) {
6+
var classDisplayName = impGR.getValue('u_class');//column name as in staging table
7+
var supportGroupName = impGR.getValue('u_support_group');//column name as in staging table
8+
var managedByGroupName = impGR.getValue('u_managed_by_group');//column name as in staging table
9+
10+
if (!classDisplayName) {
11+
gs.warn('[Import] Skipping row with empty class.');
12+
continue;
13+
}
14+
15+
var classTable = '';
16+
var dbObjGR = new GlideRecord('sys_db_object');
17+
dbObjGR.addQuery('label', classDisplayName);
18+
dbObjGR.addEncodedQuery('nameSTARTSWITHu_cmdb_ci^ORnameSTARTSWITHcmdb_ci');//custom CMDB table names are prepended with u_cmdb_ci
19+
dbObjGR.query();
20+
if (dbObjGR.next()) {
21+
22+
classTable = dbObjGR.getValue('name');
23+
}
24+
25+
if (!classTable) {
26+
gs.warn('[Import] Could not find table for class: ' + classDisplayName);
27+
continue;
28+
}
29+
30+
var supportGroupId = '';
31+
var managedByGroupId = '';
32+
33+
var groupGR = new GlideRecord('sys_user_group');
34+
groupGR.addQuery('name', 'IN', supportGroupName + ',' + managedByGroupName);
35+
groupGR.query();
36+
while (groupGR.next()) {
37+
var name = groupGR.getValue('name');
38+
if (name === supportGroupName) supportGroupId = groupGR.getUniqueValue();
39+
if (name === managedByGroupName) managedByGroupId = groupGR.getUniqueValue();
40+
}
41+
42+
if (!supportGroupId || !managedByGroupId) {
43+
gs.warn('[Import] Missing group sys_id for: ' + supportGroupName + ' or ' + managedByGroupName);
44+
continue;
45+
}
46+
47+
48+
var ciGR = new GlideRecord(classTable);
49+
ciGR.addEncodedQuery('Optional-Filters');
50+
ciGR.query();
51+
if (!ciGR.hasNext()) {
52+
gs.warn('[Import] No CI found in ' + classTable + ' with name: ' + classDisplayName);
53+
}
54+
55+
while (ciGR.next()) {
56+
ciGR.setValue('support_group', supportGroupId);
57+
ciGR.setValue('managed_by_group', managedByGroupId);
58+
ciGR.update();
59+
}
60+
}

0 commit comments

Comments
 (0)