|
| 1 | +* |
| 2 | + * Script Name: Clean up non-licensable software install normalization data |
| 3 | + * Description: Finds all software installation records that have a normalized product, |
| 4 | + * but where the normalized product is not marked as licensable. |
| 5 | + * It then clears the 'norm_product' and 'norm_publisher' fields on these records. |
| 6 | + * Purpose: This prevents non-licensable software installations from being included in |
| 7 | + * Software Asset Management (SAM) reconciliation and ensures data accuracy |
| 8 | + * for reporting. |
| 9 | + * |
| 10 | + * Execution: Typically run as a Fix Script or Scheduled Job. |
| 11 | + */ |
| 12 | + |
| 13 | +// Initialize a GlideRecord object for the Software Installation table. |
| 14 | +var gr = new GlideRecord('cmdb_sam_sw_install'); |
| 15 | + |
| 16 | +// Add an encoded query to find the specific records to be updated. |
| 17 | +// 'norm_productISNOTEMPTY' finds records where the normalized product field is not empty. |
| 18 | +// '^' acts as the AND operator in an encoded query. |
| 19 | +// 'norm_product.product_type!=licensable' filters for records where the product type |
| 20 | +// of the normalized product is not 'licensable'. |
| 21 | +gr.addEncodedQuery('norm_productISNOTEMPTY^norm_product.product_type!=licensable'); |
| 22 | + |
| 23 | +// Clear the normalized product field by setting its value to an empty string. |
| 24 | +gr.setValue('norm_product', ''); |
| 25 | + |
| 26 | +// Clear the normalized publisher field. |
| 27 | +gr.setValue('norm_publisher', ''); |
| 28 | + |
| 29 | +// This is a bulk update, so business rules are disabled for better performance. |
| 30 | +// Disabling workflows (and business rules) prevents recursive updates and avoids triggering |
| 31 | +// unnecessary logic for each record during this cleanup process. |
| 32 | +gr.setWorkflow(false); |
| 33 | + |
| 34 | +// Execute the update on all records that match the query conditions. |
| 35 | +// The updateMultiple() method is more efficient for batch operations than iterating through each record with a while loop and calling update(). |
| 36 | +gr.updateMultiple(); |
0 commit comments