I saw this answer about aggregating a field from nested json, but when I try to do so with a hidden field prefixed by __, I get the “Could not access blank value” message in the payload. Is there a way to aggregate nested hidden fields?
Hi can you post some screenshots of what you are trying to do?
are you putting JSON in a hidden field? how are you referencing the field in your formula
Thanks for replying!
Here’s a screenshot of a minimal example. When I generate, the thing.total field appropriately sums the ‘a_number’ field, but the thing.hidden_total field just generates “error: Could not access blank value: Use || to provide a default value for blank fields. Example: (my_field || 0) + 1”
Here’s an example of aggregating an attribute in an array: https://www.mockaroo.com/b6fe2a30.
I use the following formula:
items.map {|item| item["price"]}.sum
Your example is slightly more complicated because it has nested arrays. Here’s an example which shows you how to do that:
So it looks like that runs into the same issue - if the field to sum is NOT hidden, it works fine, but if it references a hidden field it returns the “Could not access blank value” message.
Yes, that appears to be correct. Nested arrays are generated and hidden values are removed before they are made available to the parent. So you cannot aggregate on a hidden value.
There is, however, another way to hide the field after aggregation, by using an inline formula on the outer array. I’ve updated the example to show this:
https://www.mockaroo.com/351243d0
The inline formula for the outer array is:
this.map do |outer|
outer.merge({
items: outer["items"].map do |item|
item.delete("price")
item
end,
})
end
That looks promising! But I don’t seem to have access to the example.
Sorry, I posted the wrong link. Here you go: Mockaroo - Random Data Generator and API Mocking Tool | JSON / CSV / SQL / Excel