User submits value, gets added as an array element to their column

I have a system for users to “donate” a virtual currency to each other for the purposes of “spending” on things. I’m running into an issue.

I want to allow User A to “donate” money to User B and have the donation be recorded in “Donation Made” column in User A’s row, containing data “donation amount, User B ID.” This way, we can look up who donated, how much they donated, and who it was donated to.

BUT! I want to be able to add multiple donations as though they are multiple array elements. So if User A donates to User B, then later donates to User C, I want there to be two array elements in the “Donation Made” column for each donation (“donation amount, User B ID” and “donation amount, User C ID”).

Right now, I have a donation page where User A can select User B from a list and then write in a value, which are both temporarily stored in the All Users table and combined into a “Donation Processing” column as “donation amount, User B.” I want to make a function call in a workflow that would take the “Donation Processing” column’s value, add it to User A’s “Donations Made” column, and then let User A continue to make new donations that get added to just the one cell for their row in the “Donations Made” column.

Is this possible?

Yes, it’s possible. To clarify, the user table have number columns with a raw value of “donation made” and “donation amount” but also another column of an array of these items as a “donation log” of sorts?

Before fleshing out the solution, is there a reason why you’re not just logging the donations in a Glide Big Table and then just rolling up the amounts?

I had already thought about creating another table/big table as a “donation ledger” and rolling up the results, but I don’t want to eat away at my row allocation. This app I’m developing will be used by over 1000 people concurrently, each making multiple donations throughout a week-long program, and I also wanted to use a Big Table as a chat log. I’m worried that we would eat up the 50k or 100k allocation quickly.

Right now, I’m looking at 3 rows (User A, User B, and User C) and 4 columns (User ID, Donations Made, Donation Amount, Donation Processing).

“Donations Made” will be my running array list of all donations made by the row’s user.

“Donation Amount” is the temporary value that the user is entering in the Number Entry form component.

“Donation Processing” is a template consisting of the donated-to user and the amount being donated.

I recommend using JSON. Here’s a tutorial that uses restaurant orders as an example, but the process is similar:

2 Likes

This was actually very helpful! I am now able to get the values submitted such that each individual donation creates a 3-piece “Donor, value, recipient” JSON object and stores all of those individual objects inside one cell.

But I’m having trouble figuring out how to then separately query this so I can generate a report. For example, I want each recipient to be able to see a written out list of every person who donated to them, how much was donated, and the total donated. It would be nice to have timestamps, too, but I figure I can easily add those if the other data can be sorted and displayed. Do you have any suggestions? I’m thinking I have to make a JSON Template that uses each unique UserID to format the data somehow or filter it out, then use a JSON Query to pull it apart?

(I don’t have any experience with JSONata though I’m not too much of a novice with programming logic.)

Yes, you’ll need to pull them apart using a helper table. I think the video goes into that no?

Yes, but I’d rather not have to use a second table. The app I’m making will have around 1000 users making anywhere from 0 to n donations so coming up with a helper table would be pretty big and complicated.

I was thinking that I could try to make a Query JSON column that could check the Donations column, look for “Recipient is UserID” for a the UserID in a particular row, then report back all of the “Donation amount” values. A rollup column would then add them up. Is this not feasible?

The idea should be joining all JSON elements in an array.

Then, use JSONata with dynamic querying template to query out what you need.

It should be possible, but it’s complicated.

So then the next question I have: how do I create a JSON Query that pulls a value from one column (“UserID”) and runs a lookup on a JSON Object?

Can you show me a sample of the JSON object you have, and an ideal outcome you want from that JSON object? In each row, I assume you’re having a list of all donations that the person has made?

Let’s say I have { “UserID”: 12345 } as my object.

I want to run a Query that calls UserID as the lookup criteria from an adjacent column in the same row and return 12345 as the result.

Isn’t what you have a JSON array of all donations and you want to run that against a specific “recipient ID”?

Yes, I have the donation amounts saved as {“UserID donated to” : donation amount}

In the column for the UserID that is receiving the donations, I want to run a lookup on all the values in the “donation” column to try and find the donation amounts that are made towards that UserID.

Ok I have a prototype for you.

I’m simulating your data like this. In theory, as you’re storing it as an array, you need a joined list column to join them together first, and then a template column to wrap it in brackets.

[
J
]

With J being the joined JSON mentioned above.

Now, I used a series of columns to get:

Donations made to each user.

Sum of donations a user has received.

Sum of donations user X has made to user Y.

Please check them in the Donations table here.

1 Like

That’s amazing, thank you!

Just one question: what exactly is in the JSON Query columns? I can’t get it to work quite like you did and the link to the table you shared doesn’t let me see the code.

EDIT: Nevermind, I figured out that I needed to make a Copy of the table to play with it myself. Thanks! Problem solved!

1 Like

Happy to help!