- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2023 10:38 AM
Hi everyone,
I need to create a script, it must has the next criteria:
- When the Assignment Group field of a Product changes to a non-empty value, the new value should be copied to the Assignment Group field of all Themes that are part of that Product
- When the Assignment Group field of a Product changes to a non-empty value, the new value should be copied to the Assignment Group field of all Epics that are part of that Product}
I need to create:
- Create a BR in the "Product" table (cmdb_application_product_model), triggered when the value of the "Assignment group" field changes and the new value is empty.
- BR must create a GlideRecord to find all the records of "Theme" (scrum_theme) in which the value of the "product" field is the Product that triggered BR
- For each Theme record found by GlideRecord, update the value of its "Assignment group" field for the same value of the "Assignment group" field of the Product that triggered BR
- BR should create another GlideRecord to find all the records of "Epic" (rm_epic) in which the value of the "product" field is the Product that triggered BR
- For each Epic record found by GlideRecord, update the value of its "Assignment group" field for the same value of the "Assignment group" field of the Product that triggered BR
Thanks u!!!!!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 09:52 AM
Hi @Daiana Botta,
An update if you're still interested. I added custom "Assignment Group" fields. New BR definition based on your requirements:
And 'enhanced' script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.info("syncProductFields: Processing Product: " + current.display_name + ".");
// Update rm_epic table with cmdb_application_product_model assignment group
var rmEpic = new GlideRecord('rm_epic');
rmEpic.addQuery('product', current.sys_id); // cmdb_application_product_model record
rmEpic.query();
gs.info("syncProductFields: Found " + rmEpic.getRowCount() + " rm_epic records to update.");
while (rmEpic.next()) {
gs.info("syncProductFields: Updating " + rmEpic.number + " with group: " + current.u_assignment_group + ".");
rmEpic.assignment_group = current.u_assignment_group;
rmEpic.update();
}
// Update scrum_theme table cmdb_application_product_model assignment group
var scrumTheme = new GlideRecord('scrum_theme');
scrumTheme.addQuery('product', current.sys_id); // cmdb_application_product_model record
scrumTheme.query();
gs.info("syncProductFields: Found " + scrumTheme.getRowCount() + " scrume_theme records to update.");
while (scrumTheme.next()) {
gs.info("syncProductFields: Updating " + scrumTheme.number + " with group: " + current.u_assignment_group + ".");
scrumTheme.u_assignment_group = current.u_assignment_group;
scrumTheme.update();
}
})(current, previous);
If you choose this approach. As mentioned above by OlaN, there are other approaches for the desired outcome.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 09:52 AM
Hi @Daiana Botta,
An update if you're still interested. I added custom "Assignment Group" fields. New BR definition based on your requirements:
And 'enhanced' script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.info("syncProductFields: Processing Product: " + current.display_name + ".");
// Update rm_epic table with cmdb_application_product_model assignment group
var rmEpic = new GlideRecord('rm_epic');
rmEpic.addQuery('product', current.sys_id); // cmdb_application_product_model record
rmEpic.query();
gs.info("syncProductFields: Found " + rmEpic.getRowCount() + " rm_epic records to update.");
while (rmEpic.next()) {
gs.info("syncProductFields: Updating " + rmEpic.number + " with group: " + current.u_assignment_group + ".");
rmEpic.assignment_group = current.u_assignment_group;
rmEpic.update();
}
// Update scrum_theme table cmdb_application_product_model assignment group
var scrumTheme = new GlideRecord('scrum_theme');
scrumTheme.addQuery('product', current.sys_id); // cmdb_application_product_model record
scrumTheme.query();
gs.info("syncProductFields: Found " + scrumTheme.getRowCount() + " scrume_theme records to update.");
while (scrumTheme.next()) {
gs.info("syncProductFields: Updating " + scrumTheme.number + " with group: " + current.u_assignment_group + ".");
scrumTheme.u_assignment_group = current.u_assignment_group;
scrumTheme.update();
}
})(current, previous);
If you choose this approach. As mentioned above by OlaN, there are other approaches for the desired outcome.