Skip to content

Commit 21b68e2

Browse files
Create softwareCreation.js
1 parent 43b8753 commit 21b68e2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var SoftwareUtils = Class.create();
2+
SoftwareUtils.prototype = {
3+
initialize: function() {},
4+
5+
softwareUtil: function(deviceId, softwareId) {
6+
var softwareInstance = new GlideRecord('cmdb_software_instance');
7+
gs.info("Transformation" + deviceId + " " + softwareId);
8+
softwareInstance.addQuery('installed_on', deviceId);
9+
softwareInstance.addQuery('software', softwareId);
10+
softwareInstance.query();
11+
12+
if (!softwareInstance.next()) {
13+
gs.info("Transformation inside the loop");
14+
var newSoftwareInstance = new GlideRecord('cmdb_software_instance');
15+
newSoftwareInstance.initialize();
16+
newSoftwareInstance.setValue('installed_on', deviceId);
17+
newSoftwareInstance.setValue('software', softwareId);
18+
newSoftwareInstance.insert();
19+
}
20+
},
21+
22+
type: 'SoftwareUtils'
23+
};
24+
25+
26+
Transform Script Example
27+
28+
Used within a Transform Map Script to ensure the relationship between the imported software record and its device is maintained.
29+
30+
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
31+
var ninjaSoftware = new global.SoftwareUtils();
32+
ninjaSoftware.softwareUtil(source.u_device_sys_id, target.getUniqueValue());
33+
})(source, map, log, target);

0 commit comments

Comments
 (0)