How to dynamically increase the value of an attribute with Liquid

  • 13 October 2023
  • 0 replies
  • 45 views

Introduction

This article will guide you on how to increment an attribute value dynamically in a workflow. You can update attribute values in a workflow using the ‘Create or Update Person’ action.

Problem

The challenge was configuring a 'Create or Update Person' action in the workflow where the attribute should increase dynamically. For example in this use case, each time a person made a referral, the value of 'No. Referrals' attribute should increase by one. Instead, it was showing a static value '1', not growing per each referral as it ought to.

Solution

By employing the use of a liquid code, this problem was resolved. This liquid code checks if a customer already has a value in the 'No. Referrals' attribute and, if so, increments the existing value by one. If the customer doesn't have any previous value in the attribute, it assigns a value of one to start the counting process. This modification enables the 'No. Referrals' value to increase dynamically.

Below is the screenshot of the solution code:


Solution code screenshot

This Liquid uses an if condition:

{% if customer["No. Referrals"] %}{{customer["No. Referrals"] | plus:1}}{% else %}1{% endif %}

 


0 replies

Be the first to reply!

Reply