|
| 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