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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2024 04:29 AM
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 -
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 ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2024 11:00 PM - edited ‎09-24-2024 11:03 PM
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!