diff --git a/Specialized Areas/Fix scripts/Remediate Non-licensable software install normalization/README.md b/Specialized Areas/Fix scripts/Remediate Non-licensable software install normalization/README.md new file mode 100644 index 0000000000..6083b9e57f --- /dev/null +++ b/Specialized Areas/Fix scripts/Remediate Non-licensable software install normalization/README.md @@ -0,0 +1,27 @@ +Remmediate Licensing for non - Licensable Software Installs + +This repository contains a ServiceNow server-side script designed for a data cleanup operation related to Software Asset Management (SAM) installations. The script targets and updates specific records on the cmdb_sam_sw_install table to maintain data accuracy. +Note: This is a working workaround for a bug in Servicenow XANADU SAM application. + +Overview +The primary purpose of this script is to ensure that software installations identified as non-licensable do not retain normalized product or publisher information. This prevents these specific records from being included incorrectly in SAM reconciliation and reporting. By clearing the normalization fields on these non-licensable items, the script improves data quality and the integrity of software asset reporting. + +Key functions +Targeting non-licensable records: The script uses an encoded query to find all software installation records that have a populated norm_product field, but whose associated product record is not marked as licensable. + +Clearing fields: It specifically clears the norm_product and norm_publisher fields on all matching records. + +Performance optimization: The script is designed for bulk operations and optimizes performance by disabling business rules and workflows (gr.setWorkflow(false);) during the update process. + +Usage +This script is intended to be executed in a ServiceNow instance, typically as a: + +Fix Script: A one-time execution for a specific data cleanup task. +Scheduled Job: Can be scheduled to run periodically to maintain data consistency over time. + +Important considerations +Backup: As with any data manipulation script, it is highly recommended to test the script thoroughly in a sub-production environment first. Running it on production data should be done with a prior backup or on a limited set of records initially. +Performance: The updateMultiple() method is used for efficiency. The setWorkflow(false) call prevents unnecessary business rule execution and significantly improves performance during large batch updates. +Dependency: The script relies on the Software Asset Management (SAM) Normalization feature being active, as it targets fields populated by that process. + + diff --git a/Specialized Areas/Fix scripts/Remediate Non-licensable software install normalization/script.js b/Specialized Areas/Fix scripts/Remediate Non-licensable software install normalization/script.js new file mode 100644 index 0000000000..ba49e6f407 --- /dev/null +++ b/Specialized Areas/Fix scripts/Remediate Non-licensable software install normalization/script.js @@ -0,0 +1,36 @@ +/* +* Script Name: Remediate Non-licensable software install normalization +* Description: Finds all software installation records that have a normalized product, +* but where the normalized product is not marked as licensable. +* It then clears the 'norm_product' and 'norm_publisher' fields on these records. +* Purpose: This prevents non-licensable software installations from being included in +* Software Asset Management (SAM) reconciliation and ensures data accuracy +* for reporting. +* +* Execution: Typically run as a Fix Script or Scheduled Job. +*/ + +// Initialize a GlideRecord object for the Software Installation table. +var gr = new GlideRecord('cmdb_sam_sw_install'); + +// Add an encoded query to find the specific records to be updated. +// 'norm_productISNOTEMPTY' finds records where the normalized product field is not empty. +// '^' acts as the AND operator in an encoded query. +// 'norm_product.product_type!=licensable' filters for records where the product type +// of the normalized product is not 'licensable'. +gr.addEncodedQuery('norm_productISNOTEMPTY^norm_product.product_type!=licensable'); + +// Clear the normalized product field by setting its value to an empty string. +gr.setValue('norm_product', ''); + +// Clear the normalized publisher field. +gr.setValue('norm_publisher', ''); + +// This is a bulk update, so business rules are disabled for better performance. +// Disabling workflows (and business rules) prevents recursive updates and avoids triggering +// unnecessary logic for each record during this cleanup process. +gr.setWorkflow(false); + +// Execute the update on all records that match the query conditions. +// The updateMultiple() method is more efficient for batch operations than iterating through each record with a while loop and calling update(). +gr.updateMultiple();