Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

})( );
Original file line number Diff line number Diff line change
@@ -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 = <ServiceName> + “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.
Loading