Auto Create a Relationship between 2 cmdb table, when a record is being created

Bijay Kumar Sha
Giga Guru

Hi,

I wanted to auto create a relationship between cmdb_ci_ec2_instance and corresponding cmdb_ci_aws_account (this is a reference filed available in the ec2 instance record). My requirement is whenever a new ec2 instance record is being create in cmdb_ci_ec2_instance table with install status as 'Installed' (1), then a relationship should be created with the aws account record which is a reference field available in the same ec2 instance record. 

 

I've created below BR to create and remove the relationship if there is a change in the Install status of the ec2 instance record from install to dispose or vice versa. Don't know if it'll work for new ec2 instance record creation or not -

 

BijayKumarSha_0-1727177301989.png

 

BijayKumarSha_1-1727177338696.png


Can anyone please let me know that do i need to create a new BR for insert operation only or any modification required in existing BR ?

1 REPLY 1

Daniel Borkowi1
Mega Sage

Hi @Bijay Kumar Sha, on this BR should work - did you realized any issues? I only recommend to check in case 1, if the relationship is already existing. Because you maybe have more states than this 2 and it could happen that you switch to state "installed" twice or more.

For case 2 I would switch to:

 

ciRelationship_del.deleteMultiple();

 

Instead of looping.

Greets
Daniel

Please mark reply as Helpful/Correct, if applicable. Thanks!