- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 12:45 PM
Hi All,
Can we update an Environment field for child class CI, as per parent class I? Ex: if my Server is parent class and it is in "Production" can Child class like Memory , disk , disk partition can also be marked as "Production"
PaulSylo
Kindly mark "helpful", if this helps, or Mark as "Accepted " if it solves your issues !
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 02:37 PM
Hi @PaulSylo ,
Yes, this can be done using a after business rule, when the Environment field on the parent CI is updated, the same value is propagated to its related child CIs.
You can follow the below logic and update the scripts as per your instance.
(function executeRule(current, previous /*null when async*/) {
if (current.environment != previous.environment) {
var childCIs = new GlideRecord('child_class_table'); // Replace 'child_class_table' with the actual table of child CIs
childCIs.addQuery('parent', current.sys_id);
childCIs.query();
while (childCIs.next()) {
childCIs.environment = current.environment; // Update the Environment field
childCIs.update();
}
}
})(current, previous);
Note: Update the fields, Table names as per your instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2024 09:02 AM
You can make @Community Alums’s correct solution more efficient by using ‘updateMultiple(), which will do all the updates as a single database call vs looping and saving each record. Replace lines 5 -9 with the following.
childCIs.query();
childCIs.setValue('environment', currentEnvironment);
childCIs.updateMultiple();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 02:37 PM
Hi @PaulSylo ,
Yes, this can be done using a after business rule, when the Environment field on the parent CI is updated, the same value is propagated to its related child CIs.
You can follow the below logic and update the scripts as per your instance.
(function executeRule(current, previous /*null when async*/) {
if (current.environment != previous.environment) {
var childCIs = new GlideRecord('child_class_table'); // Replace 'child_class_table' with the actual table of child CIs
childCIs.addQuery('parent', current.sys_id);
childCIs.query();
while (childCIs.next()) {
childCIs.environment = current.environment; // Update the Environment field
childCIs.update();
}
}
})(current, previous);
Note: Update the fields, Table names as per your instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2024 09:02 AM
You can make @Community Alums’s correct solution more efficient by using ‘updateMultiple(), which will do all the updates as a single database call vs looping and saving each record. Replace lines 5 -9 with the following.
childCIs.query();
childCIs.setValue('environment', currentEnvironment);
childCIs.updateMultiple();