Skip to content

Commit 0d9e202

Browse files
Software Installation Relationship Creator (#2241)
* Create softwareCreationREADME.md * Create softwareCreation.js
1 parent c58f202 commit 0d9e202

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-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);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
This script automates the creation of Software Instance relationships in the CMDB during data import or transformation.
2+
It ensures that each discovered or imported software record is correctly linked to the device on which it is installed, without creating duplicates.
3+
4+
5+
6+
The SoftwareUtils Script Include provides a utility function that checks whether a specific software (cmdb_software_product) is already related to a device (cmdb_ci_computer, cmdb_ci_server, etc.) through a Software Instance (cmdb_software_instance) record.
7+
8+
If the relationship does not exist, it creates a new software instance automatically.
9+
10+
This logic can be used directly within a Transform Map Script (onAfter) during software data import.

0 commit comments

Comments
 (0)