- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 03:16 AM - edited 04-22-2024 03:17 AM
Hello Experts,
I am looking to help optimize the script. I need to remove a record an old record from a table. When a CI is moved from one assignment group to another a new record is created in the following table 'cmdb_group_contains_ci'. We are importing all the information from through a data source in a table transform map. This is what the script I wrote. Can someone help quickly ? I am using a onComplete script.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var dupCI = new GlideAggregate('cmdb_group_contains_ci');
dupCI.addAggregate('COUNT');
dupCI.groupBy('configuration_item');
dupCI.query();
if (dupCI.getAggregate('COUNT') > 1)
while (dupCI.next()) {
var dup1 = new GlideRecord("cmdb_group_contains_ci")
dup1.addQuery('configuration_item', dup1.configuration_item);
dup1.orderBy('sys_updated_on');
dup1.query();
dup1.next();
while (dup1.next())
dup1.deleteRecord();
}
})(source, map, log, target);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 04:42 AM
Try this code :
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var dupCI = new GlideAggregate('cmdb_group_contains_ci');
dupCI.addAggregate('COUNT');
dupCI.groupBy('configuration_item');
dupCI.query();
while (dupCI.next()) {
if (dupCI.getAggregate('COUNT') > 1) {
var dup1 = new GlideRecord("cmdb_group_contains_ci");
dup1.addQuery('configuration_item', dupCI.configuration_item);
dup1.query();
while (dup1.next()) {
dup1.deleteRecord();
}
}
}
})(source, map, log, target);
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 04:42 AM
Try this code :
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var dupCI = new GlideAggregate('cmdb_group_contains_ci');
dupCI.addAggregate('COUNT');
dupCI.groupBy('configuration_item');
dupCI.query();
while (dupCI.next()) {
if (dupCI.getAggregate('COUNT') > 1) {
var dup1 = new GlideRecord("cmdb_group_contains_ci");
dup1.addQuery('configuration_item', dupCI.configuration_item);
dup1.query();
while (dup1.next()) {
dup1.deleteRecord();
}
}
}
})(source, map, log, target);
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 04:56 AM
Thank You Sohail, just wanted to ask you one more question.
For instance
In the table...a CI is moved from one group (which becomes the old group) and moved to a new group, I want to just delete the CI which is associated associated with the old group & the new group stays with the CI. I will still check the script and get back to you when it works.