Business App Owner and Managed By Cascade

Community Alums
Not applicable

I have a requirement to sync business app to mapped application service for the following fields owned_by and managed_by when the bus app owned_by and managed_by changes.   I am assuming it needs to be cmbd ci relationship table but not sure.  Any assistance is appreciated.

Thanks,

Chad

1 ACCEPTED SOLUTION

Hi @Community Alums 

On Which table this BR is written? Business Application or Relationship table.

 

It should be on business app table.

 

And add logs inside the if condition, so that we can be sure of the query returned results.

Thanks,
Anvesh

View solution in original post

5 REPLIES 5

AnveshKumar M
Tera Sage
Tera Sage

Hi @Community Alums 

Yes you can use cmdb_rel_ci table. Query should be like parent is current.sys_id and type is Consumes::Consumed By and the child class should be like cmdb_ci_appl. Then update the data in the fetched applications. You can change these relation ship type and Child Class type as per your need. Some script like below you can use.

 

After - Update Business Rule:

(function executeRule(current, previous /*null when async*/) {

	var relGr = new GlideRecord("cmdb_rel_ci");
	relGr.addEncodedQuery("type=41008aa6ef32010098d5925495c0fb94^child.sys_class_name=cmdb_ci_appl^parent=" + current.getUniqueValue()); //Change Type and Child Class type as per your need
	relGr.query();

	while(relGr._next()){
		var app = relGr.getValue('child');
		var appGr = new GlideRecord("cmdb_ci_appl");
		if(appGr.get("sys_id", app)){
			appGr.owned_by = current.owned_by;
			appGr.managed_by = current.managed_by;
			appGr.update();
		}
	}

})(current, previous);

 

AnveshKumarM_0-1701915873681.png

 

AnveshKumarM_1-1701915887531.png

 

AnveshKumarM_2-1701915902610.png

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

Community Alums
Not applicable

Hello Anvesh,

I appreciate the assistance.  I made the changes but it is not working.

var relGr = new GlideRecord("cmdb_rel_ci");
relGr.addEncodedQuery("parent.sys_class_name=cmdb_ci_business_app^type=41008aa6ef32010098d5925495c0fb94^child.sys_class_name=cmdb_ci_service_discovered^parent=" + current.getUniqueValue()); //Change Type and Child Class type as per your need
relGr.query();

while(relGr._next()){
var app = relGr.getValue('child');
var appGr = new GlideRecord("cmdb_ci_service_discovered");
if(appGr.get("sys_id", app)){
appGr.owned_by = current.owned_by;
appGr.managed_by = current.managed_by;
appGr.update();
}

 

Screenshot 2023-12-07 at 5.59.24 PM.png

Hi @Community Alums 

On Which table this BR is written? Business Application or Relationship table.

 

It should be on business app table.

 

And add logs inside the if condition, so that we can be sure of the query returned results.

Thanks,
Anvesh

Community Alums
Not applicable

@AnveshKumar M Hello, any assistance is appreciated.  Thanks, Chad