diff --git a/Server-Side Components/Background Scripts/TagsCreationFromDCI b/Server-Side Components/Background Scripts/TagsCreationFromDCI new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Server-Side Components/Background Scripts/TagsCreationFromDCI @@ -0,0 +1 @@ + diff --git a/Specialized Areas/ITOM/Bulk Location Update/TagsCreationFromDCIgroup.js b/Specialized Areas/ITOM/Bulk Location Update/TagsCreationFromDCIgroup.js new file mode 100644 index 0000000000..074820fa2a --- /dev/null +++ b/Specialized Areas/ITOM/Bulk Location Update/TagsCreationFromDCIgroup.js @@ -0,0 +1,41 @@ +(function() { + + + var dynamicGroups = new GlideRecord('cmdb_ci_query_based_service'); //Dynamic Ci group + dynamicGroups.addQuery('cmdb_group', '!=', ''); + dynamicGroups.query(); + + var groupSysIds = []; + while(dynamicGroups.next()) { + groupSysIds.push(dynamicGroups.cmdb_group); + } + + + if (groupSysIds.length > 0) { + var cmdbGroupContainsCI = new GlideRecord('cmdb_group_contains_ci'); //Group contains CI's + cmdbGroupContainsCI.addQuery('group', 'IN', groupSysIds.join(',')); + cmdbGroupContainsCI.query(); + + + while (cmdbGroupContainsCI.next()) { + + var keyValue = new GlideRecord('cmdb_key_value'); + keyValue.addQuery('configuration_item', cmdbGroupContainsCI.configuration_item); + keyValue.addQuery('key', 'Application'); + keyValue.query(); + + if (!keyValue.next()) { + // Only insert if not already present + keyValue.initialize(); + keyValue.setValue('configuration_item', cmdbGroupContainsCI.configuration_item); + keyValue.setValue('key', 'Application'); + keyValue.setValue('value', dynamicGroups.name + 'AS'); + keyValue.insert(); + + // Log only for new entries created (optional) + gs.info('Created key-value for CI: ' + cmdbGroupContainsCI.configuration_item + ' in group: ' + dynamicGroups.name + ', SysID: ' + keyValue.sys_id); + } + } + } + +})( ); diff --git a/Specialized Areas/ITOM/Bulk Location Update/TagsCreationFromDCIgroups.README.md b/Specialized Areas/ITOM/Bulk Location Update/TagsCreationFromDCIgroups.README.md new file mode 100644 index 0000000000..e398f06431 --- /dev/null +++ b/Specialized Areas/ITOM/Bulk Location Update/TagsCreationFromDCIgroups.README.md @@ -0,0 +1,10 @@ +This script automatically creates key-value entries for Configuration Items (CIs) that belong to query-based CMDB groups, ensuring consistent tagging and service association within the CMDB. +It is particularly useful for maintaining Application-level key associations (key = "Application") dynamically — based on group membership from Query-Based Services (cmdb_ci_query_based_service). + +This script automates the process of creating records in the cmdb_key_value table for all CIs belonging to query-based service groups (cmdb_ci_query_based_service) that are linked with CMDB groups. +It ensures that: +* Each CI gets a key-value pair where
key = “Application” and
value = + “AS” +* No duplicate key-value entries are created for the same CI. + + +Build the Tag based mapping define the key and values for every application service and build the map,Here I am grouping CI's with DCI CI Groups.