
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 07:30 AM
Hi,
I've 2 tables in cmdb. cmdb_ci_ec2_instance and cmdb_ci_aws_account.
In the form of one record available in 'cmdb_ci_ec2_instance' table, there is a reference field which is a record from 'cmdb_ci_aws_account'. Please find a sample screenshot as below -
In the 'cmdb_rel_ci' table, I've created a relationship between above tables as 'Depends On::Used By'. where 'cmdb_ci_ec2_instance' is a parent table of 'cmdb_ci_aws_account'.
Now, my requirement is whenever, the Install Status of any record from 'cmdb_ci_ec2_instance' changes to 'Installed', then automatically the relationship should get created to the AWS Cloud account which is mentioned in the reference field of that form.
And, whenever the Install Status of the any record from 'cmdb_ci_ec2_instance' changes to 'Disposed', then automatically the relationship should get removed from that AWS Cloud account which is mentioned in the reference field of that form.
How to get this done?
Any help ?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 06:50 AM
Hi @Bert_c1 ,
Below is the updated BR -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 09:38 AM - edited 08-01-2024 01:54 PM
Hi,
You may achieve your goal using a business rule defined on the 'cmdb_ci_ec2_instance' table as shown below.
The script logic is:
(function executeRule(current, previous /*null when async*/) {
// Check install_status
if (current.install_status == 1) { // value for "Installed"
var ciRelationship = new GlideRecord('cmdb_rel_ci');
ciRelationship.initialize();
ciRelationship.parent = current.sys_id;
ciRelationship.child = current.u_aws_account; //reference field for cmdb_ci_aws_account
// set any other fields as desired
ciRelationship.insert();
}
if (current.install_status == 2) { // value for "Disposed"
var ciRelationship = new GlideRecord('cmdb_rel_ci');
ciRelationship.addQuery('parent', current.sys_id.toString());
ciRelationship.addQuery('child', current.u_aws_account.toString()); //reference field for cmdb_ci_aws_account
ciRelationship.query();
while (ciRelationship.next()) {
ciRelationship.deleteRecord();
}
}
})(current, previous);
I do not have a reference field on the 'cmdb_ci_ec2_instance' table to a record in the 'cmdb_ci_aws_account' table, seems you do have that field. I assummed it may have name = 'u_aws_account' in the above. I also had to defined two choice values for install_status: 1 - Installed and 2 - Disposed.
If the above doesn't work for you, please post details on those aspects.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 03:32 AM
Hi @Bert_c1 ,
It's almost correct except one thing. The relationship 'Type' is missing. I see relationship is getting created but type is missing. How I can integrate the Relationship Type between these 2 table?
Can you please let me know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 06:33 AM
Hi @Bijay Kumar Sha,
I reviewed again, and see today that I reference a non-existing table: "cmdb_ci_rel". Please be specific on what fields are in play here. Where/how any relationship is stored.
1. Reference field on 'cmdb_ci_ec2_instance' to the 'cmdb_ci_aws_account' table. My guess is that field is named 'u_aws_account'.
2. Is there a reference field on the 'cmdb_ci_aws_account' to a record in the 'cmdb_ci_ec2_instance'?
3. What table does 'Type' exist on?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 06:50 AM
Hi @Bert_c1 ,
Below is the updated BR -