Problem incrementing counter in Data Store (add() → '0' is not a valid array)

Hi everyone,
I’m building a flow to generate sequential protocol numbers using Data Store in Make.

I created a Data Store called protocolo_counter with the following structure:

  • value → Number (Required)

  • updated_at → Date

My goal:

  • For each new email received, increment the counter for the current year (2025-000001, 2025-000002, etc.).

  • Key = year (2025, 2026…)

  • Value = last sequential number.

What I did so far:

  1. Use Get a record with Key = {{formatDate(now; "YYYY")}}.

  2. Created a Set variable to calculate the next number:

    {{ add( parseNumber( [Get a record: Record: value] ) ; 1 ) }}
    
    
  3. Then I run Update a record (Insert missing = Yes) to save the new number.

Problem:

  • When the record does not exist yet (first execution of the year), Make returns this error:

    Failed to map 'value': Function 'add' finished with error! '0' is not a valid array.
    
    

What I tried:

  • Using ifempty(...;0) before add.

  • Wrapping with parseNumber(...) to force a numeric type.

  • Still getting the same error.

My question:

  • What’s the correct way to automatically initialize this counter without having to manually create 2025 = 0 in the Data Store every January?

  • Is there a simpler/best-practice pattern for auto-incrementing numeric values in Data Store?

Thanks in advance :folded_hands:

2 Likes

Hi @1_Tabeliao_de_Notas

The easiest solution would be to create a separate scenario that runs every January 1st at midnight and inserts 0 with the current year.

That may sound counterintuitive to someone with a programming background, but that’s the way Make objectively solves problems.

@damato

First of all, thank you @damato for your reply and guidance — really appreciate your help! :folded_hands:

I’ve been trying to implement the annual sequential protocol suggested here, but I’m still running into some issues.

So far, I’ve tried:

  • Using a fixed number to initialize, but the counter does not increment correctly.

  • Using the Data Store with a key based on the year, but the value is treated as text instead of numeric, which prevents mathematical functions from working.

  • Concatenating keys, but Make doesn’t have a concat function.

  • Using the same key, which only replaces the value instead of incrementing the counter.

The community suggested creating a scenario that resets the counter back to zero every January 1st. However, my flow breaks before that, because the counter doesn’t actually increment correctly during executions.

It seems the bigger challenge here is making the counter advance properly with each execution. Has anyone been able to overcome this limitation with the Data Store in Make? Any advice would be very helpful.

Thanks again, and tagging @damato in case you can share more insights!

I built a simple scenario to test this. It searches for the current year in updated_at and retrieves the value from the Data Store. Then, it adds 1 to the value and updates the Data Store.

Instead of a Date type, I used number for the year. Then, you can add as many records as you want, with (, 0). Let’s say, for the next 100 years. That way, you’ll never have to insert a record every year. You could create logic to insert the record if it’s not found, but I just don’t think it’s necessary.

This is the scenario:

It always finds the year from the current execution time and retrieves the value from the Data Store. Watch out for the Timezone, since Brazil has more than one.

Then, it increments the value:

Finally, it updates the Data Store with the new value, using the Key from step 1:

Here’s the blueprint:

Integration Data store.blueprint.json (10.0 KB)

Hope it helps.

@damato

Hi @damato,

Thank you so much for taking the time to share this solution and even include the blueprint :folded_hands:
Really appreciate the clarity—it makes everything much easier to implement.
We’ll put it into practice right away!

Best regards,

1 Like