Error when setting value with "where"

I have a query and want to count records with a certain value. The Set Value is immediately following the query.

If I just count without a where clause it works fine and returns a value of 5
{{rebates.count()}}

If I count using where I get an error “formatter expects and array”
{{rebates.count().where(rebates[0].RebateProgramID, “==”, 8)}}
In the debug code it looks like this
{{rebates.count().where(rebates[0].RebateProgramID, “==”, 8)}}

Can you point out the error in my ways please.

Remove the [0].

The way you have it will only return a result if the very first record is = 8.

Thanks Brad, changed it and same error.
{{rebates.count().where(rebates.RebateProgramID, “==”,8)}}
On debug
{{rebates.count().where(rebates.RebateProgramID, “==”,8)}}

Also, I changed it back to the original and did use the value of the first record returned and got the same error
{{rebates.count().where(rebates[0].RebateProgramID, “==”, 8)}}

Remove count(), as by definition count() will return a single number and not an array.

Or put the .count() after the .where()…

It might help if I explained what I need it to do. The query returns multiple records. I want to set a value of the count for a specific number. Don’t need an array. Should be simple but Im evidently missing something.

  1. Run query
  2. Returns multiple records
  3. Set a value the contains the count of all records where ProductRebateID = 8
  4. ValueName =15

If I run count on the query i get the correct number of records, so assumed I would then add a where to the count. Do I need to run a repeat on the query then do it?

Have you tried Antony’s suggestion? Makes sense.

Not yet, will be back at the office in 30. It does sound like the right path to me as well.

1 Like

You should first do the where and then the count

{{ rebates.where('RebateProgramID', '==', 8).count() }}
1 Like

Perfect, thanks!!

This has been fixed in Wappler 3.7.4

This topic was automatically closed after 46 hours. New replies are no longer allowed.