Fire webhook when field value changes

Hi

How would I fire a webhook only when a certain field value changes?

The use case is: I have a model called client with a field value id_number. Whenever id_number changes I want the webhook to fire a cc task to check if the id_number exists so that I can manage / prevent duplicates.

From what I can see in the docs, the webhook is going to fire on any value being changed, not just the id_number? Often we do multiple updates to objects in the business workflow or batch updates of 100000 objects. I do not want to trigger the cc task for every little save.

Thanks.

Hi Martin,

You can specify triggering condition(s) on the webhook definition in the data model to accomplish this, regardless of the type of webhook (i.e. “ready” or “update”).

The simplest way to do this is to add an additional field on the model that you can set to null if you do not want to fire off the webhook event. For example:

<model name="client" label="Client">
        <field name="id_number" label="ID Number" type="text" />
        
        <field name="id_number_changed" label="ID Number Changed?" type="boolean" />
        
        <webhook type="update" action="evaluate_id_number_changed" name="evaluate_id_number_changed" receiver="cloudcode" >
            <field name="id_number_changed" required="true" />
        </webhook>
        <display>{id_number}</display>
</model>

The addition of the id_number_changed field in this example adds a condition that will trigger the task evaluate_number_id_changed only if the field has a value. Please note however that a non-null value (i.e. values of either false OR true) will still trigger the task, so you will want to set the value of the field to null within the task itself (ideally within the first few lines) prior to performing one or more save operations on the client model to avoid invoking the task again.

Additionally, you can embed attachment field(s) and/or belongs-to(s), as well as specify the state condition that should be met before triggering the task. Additional information can be found here: Webhooks (External) - JourneyApps Docs

I hope this helps, but if you do have any additional questions or need further clarification please do not hesitate to reach out, and I will be happy to help.

-Jon