Deleting the bound entity

To end the lifecycle of a bound entity, you write an action that deletes the entity.

An agent can delete its bound entity upon the arrival of an event. To delete the bound entity of an agent, you write a rule that sets the value of the bound entity to null. The entity is then removed from the Insight Server.

Important: Other agents are likely to have references to the entity. You must remove the references to this entity before the agent deletes it. After the entity is deleted, it is no longer possible to remove the references to this entity. For more information, see Removing references to an entity.

If an agent deletes its bound entity, other agents that are triggered by the same event continue to execute. If an agent exists that can delete the entity, then other agents should test for a null entity before using it. When the entity is deleted, the event history that is related to the entity is immediately deleted as well.

In the following example, the account entity is deleted when an account closure event arrives into the system.

when an account closure event occurs,
then
	set 'the account' to null;

The following rule checks if an order is not already delivered or in preparation before canceling it.

when a pizza order cancellation occurs
if
  'the order' is not null
  and the order status of 'the order' is not DELIVERED
  and the order status of 'the order' is not PREPARING
then
  set 'the order' to null;
  emit a new communication where
    the person is the customer of this pizza order cancellation,
    the message is "Your pizza order has been cancelled.";