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
33 changes: 33 additions & 0 deletions Specialized Areas/CMDB/CMDB Utility Scripts/softwareCreation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var SoftwareUtils = Class.create();
SoftwareUtils.prototype = {
initialize: function() {},

softwareUtil: function(deviceId, softwareId) {
var softwareInstance = new GlideRecord('cmdb_software_instance');
gs.info("Transformation" + deviceId + " " + softwareId);
softwareInstance.addQuery('installed_on', deviceId);
softwareInstance.addQuery('software', softwareId);
softwareInstance.query();

if (!softwareInstance.next()) {
gs.info("Transformation inside the loop");
var newSoftwareInstance = new GlideRecord('cmdb_software_instance');
newSoftwareInstance.initialize();
newSoftwareInstance.setValue('installed_on', deviceId);
newSoftwareInstance.setValue('software', softwareId);
newSoftwareInstance.insert();
}
},

type: 'SoftwareUtils'
};


Transform Script Example

Used within a Transform Map Script to ensure the relationship between the imported software record and its device is maintained.

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var ninjaSoftware = new global.SoftwareUtils();
ninjaSoftware.softwareUtil(source.u_device_sys_id, target.getUniqueValue());
})(source, map, log, target);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This script automates the creation of Software Instance relationships in the CMDB during data import or transformation.
It ensures that each discovered or imported software record is correctly linked to the device on which it is installed, without creating duplicates.



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.

If the relationship does not exist, it creates a new software instance automatically.

This logic can be used directly within a Transform Map Script (onAfter) during software data import.
Loading