- 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-26-2023 11:34 AM
hi,
I don't see a field "Assignment Group" defined on the 'cmdb_application_product_model' table. So your 1, 3, and 5 don't seem possible without a way to determine a related Assignment Group. 2 and 4 are possible since both those tables have reference fields to the 'cmdb_application_product_model' table. A good example of what you want to do in 2 and 4 (Update a record in another table that is related to the record in the table being updated) is the Business rule named "Sync RITM state to REQ" defined on the 'sc_req_item' table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2023 11:39 AM
Hello!
Yes, I forgot to clarify that the assignment group field does not exist and we had to create it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2023 01:45 PM
Hello Daiana,
Great, I also believe you created that on the scrum_theme table too, as I don't see 'assignment_group' defined there either, I see it on rm_epic. Given that, I have script logic that follows.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
// 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);
I don't have u_assignment_group defined on my instance for either table, I can't test. And the Condition field in the following screenshot would need to change for you.
The script is defined on the "Advanced" table. Please test in sub-prod instance. Let me know if you have questions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 02:28 AM - edited ‎07-27-2023 02:28 AM
Hi,
This requirement could be done with Flow Designer, no scripting required.
Providing a simple example below, to get you started.