Skip to main content

Entity Update with Conditional Logic

Description

This automation demonstrates complex conditional processing after entity creation. It shows how to use conditional actions to execute different logic paths based on entity field values. The automation includes queue management with different priorities, entity relationship handling, and multiple conditional branches. This pattern is essential for implementing business rules that vary based on data conditions.

Use Case

Used when a subscription is created to trigger various initialization processes. The automation adds the subscription to indexing queues, validates workflow conditions, triggers customer history tracking, and conditionally updates customer records if a valid customer relationship exists. Different actions execute based on whether the subscription has an associated customer.

Key Features

  • Multiple parallel action execution
  • Conditional action branching based on field values
  • Queue prioritization (realtime, long)
  • Complex condition evaluation with AND combinator
  • Entity relationship validation
  • Action output chaining
  • Customer data synchronization

JSON Definition

{
"key": "when_subscription_created",
"name": "When subscription created",
"app": "sal",
"entityKey": "subscription",
"triggerType": "afterCreate",
"triggerParams": {},
"actions": [
{
"name": "add to queue",
"key": "add_to_queue",
"actionTypeKey": "add_message_queue",
"params": {
"queueName": "subscription_validation",
"message": "{{{entityId: trigger.entityId}}}",
"entityId": "{{trigger.entityId}}",
"priority": "realtime"
}
},
{
"name": "Check Subscription Condition",
"key": "check_subscription_condition",
"actionTypeKey": "check_subscription_workflow_conditions",
"params": {
"subscriptionId": "{{trigger.entity.id}}"
}
},
{
"name": "Update Subscription WF Condition",
"key": "update_subscription_wf_condition",
"actionTypeKey": "workflow_step_condition_upsert",
"params": {
"entityKey": "subscription",
"entityId": "{{runbook.outputs.check_subscription_condition.subscriptionId}}",
"conditions": "{{runbook.outputs.check_subscription_condition.conditions}}"
}
},
{
"name": "add to queue subscription",
"key": "add_to_queue_subscription",
"actionTypeKey": "add_message_queue",
"params": {
"queueName": "index_subscription",
"message": "{{{subscriptionId: trigger.entity.id}}}",
"priority": "realtime"
}
}
],
"conditionalActions": [
{
"condition": {
"rules": [
{
"field": "{{trigger.entity.customer_id}}",
"value": "",
"operator": "isNotNull"
},
{
"field": "{{trigger.entity.customer_id}}",
"value": "0",
"operator": ">"
}
],
"combinator": "and"
},
"actions": [
{
"name": "add to queue customer",
"key": "add_to_queue_customer",
"actionTypeKey": "add_message_queue",
"params": {
"queueName": "index_customer",
"message": "{{{customerId: trigger.entity.customer_id}}}",
"priority": "long"
}
},
{
"name": "update customer flags",
"key": "update_customer_flags",
"actionTypeKey": "update_customer_flags_from_subscription",
"params": {
"subscriptionId": "{{trigger.entityId}}"
}
}
]
}
]
}

Notes

  • Conditional actions use rule-based evaluation with operators
  • The AND combinator requires all rules to be true
  • Queue priorities affect processing order (realtime > normal > long)
  • Action outputs are accessible via runbook.outputs.[action_key]
  • Triple braces {{{ create JSON objects in message parameters
  • Field null checks should be combined with value checks for safety
  • Multiple conditional blocks can evaluate independently