For this case BMC Discovery offers removal groups.
Basically you have to add the relationship node to a removal group each time you create or confirm it.
host := // your host node location := // your location node rel := model.rel.Location(ElementInLocation := host, Location := location); model.setRemovalGroup(rel, 'RelationshipHostToLocation');
If the location changes, Discovery will automatically delete the old relationship. For more information see the docs (model.setRemovalGroup - BMC Discovery 11.3 - BMC Documentation).
If a host is always related to a single location you could also use the model.uniquerel function (Model functions - BMC Discovery 11.3 - BMC Documentation, Section "Unique relationship functions"). Please notice the warning in the documentation regarding the parameter order.
3 of 3 people found this helpful
It would be more sensible to use model.uniquerel for this rather than removal groups, as per the template pattern template_host_location
If it is related to more than one location you can use the type attribute to distinguish the type of location.