I need to create some BR

Daiana Botta
Tera Contributor

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:

  1. 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.
  2. 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
  3. 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
  4. 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
  5. 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!!!!!!!

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Hi @Daiana Botta,

 

An update if you're still interested. I added custom "Assignment Group" fields. New BR definition based on your requirements:

 

Screenshot 2023-07-27 124242.png

 

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.

View solution in original post

5 REPLIES 5

Bert_c1
Kilo Patron

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

 

Daiana Botta
Tera Contributor

 

Hello!

Yes, I forgot to clarify that the assignment group field does not exist and we had to create it.

Bert_c1
Kilo Patron

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.

 

Screenshot 2023-07-26 164202.png

The script is defined on the "Advanced" table.  Please test in sub-prod instance. Let me know if you have questions.

OlaN
Giga Sage
Giga Sage

Hi,

This requirement could be done with Flow Designer, no scripting required.

Providing a simple example below, to get you started.

flow-update-connected-theme-records.png