I’ve recently stepped into a case in which i had to move data from a public doc to a “Backend” doc made to be private, but in which cross doc was not working correctly due to “filter” “limitations”, i’ll explain my case below.
I have doc A that is public, it is shared with “everyone who has a link”
This doc contain the personal pages or profiles of users of the doc, in my case it is a music club, so users can manage their accounts, set their “partecipate/ not partecipating” variable for each events, and others functions (like pay for entering with stripe, and others)
The data that this doc contains are all shared with all users of that doc (basically whoever opens the link)
I have then another doc, doc B, that is the Backend of that app, in which organizers can see all their club members, set their events, configure payments link with stripe, manage event partecipation and entry/exits etc
This doc instead is “locked” and just certain users can actually use it, the organizers
Now, most of the data’s comes from doc B to doc A (so, “events” table, and others, are cross-docked into doc A)
This is fine, 'cause original datas are just in the doc B, unaccessible from external users, easy to hide just creating a filtered views with just some columns visible, and then the one that is synced is that one, this is true for all tables except one, the “People” (or “Members”) table, that is into doc A
So, the problem is, how can i “lock” the table “People” in doc A, but still unlock it for it to be able to be sync into doc B?
“lock” i mean “filter out from sight”, the table is already in a locked dock in a hidden page, so user can still see it but they can take no direct action on it.
The problems is:
The “People” table must shows no data to public users, this is “easy”, we can just hide all columns and filter it for something like “rowid=0” (that is always nothing)
Like that in doc A, no data is shown, but all formulas and other tables in the same doc read datas without problems, so this act of hiding by filtering would be enough if we had just one doc
Cross doc doesnt sync rows that are filtered in the original table AND does not sync columns that are hidden, so with this configuration i get “no rows synced/available” message in doc B when trying to sync the “People” table
So, how can i show no content in doc A but still sync data to doc B?
The trick is to understand how “Cross-doc” ask for datas in doc A
Let’s start with some practical formulas
In the people table, in doc A, we’re gonna have a formula similar to this: (each row of “people” table rappresent a members, they are created in the first login in the doc with a button, that row have a column, “User”, that contains who created this row, as a user reference)
Like this, every user see just their own profile row when looking at the table, then we add some cool canvas formula, in my case 3 of them
is currentuser superuser?
is user anonymous?
Description of those
- people.filter(user=user()) - this is to understand who member (and not user) is using the app, this is to have an internal reference to who’s using the app not as a coda user but as a App Member, it’s gonna be useful to check for example if currentmembers is validated or accepted, and to see if he have payed for example iscription fees etc, before being able to partecipate in events
- if(user()=@mariobrussi, true, false) This just check if currentuser (user()) is me or someone else, this is useful to unfilter all tables if i am looking at the doc, this is pretty useful to diagnostic purposes and to edit manually the data
- Check based on user().email if current user is anonymous (i do not want anonymous user to be able to do actions and things on the doc)
So, we’re gonna use those to get our final filter formula for our People table who does those 4 things
- Show their profile if user is not anonymous
- Hide all datas if user is anonymous
- shows all data if user is superuser (actually, you’ll see in the final formula below, in this case i’ve decided to use a toggle (true/false) placed above the table, to allow also for other users that have “admin” capabilities to manually see and edit all Members datas, i could have edited the “superuser” canvas formula to check if user() is inside an extra table called “admins”, but for the moment i like this application, in future i could change it)
- shows all rows if “user()=cross doc”, this is tricky, as you can read on apis documentation, is not really clear how cross doc identify itself when talking to coda doc, and especially to coda filter formulas, so the goal here is to find a formula that is able to discriminate between a normal user, and a cross doc sync, i’ve found it after trying for HOURS and it’s the main reason why i’m writing this post!
p.s. this is the toggle i’m referencing in the formula, it says “manual control of users”
SOOOOO ARE YOU READY FOR THE FINAL FORMULA???
p.p.s. the formula who’s able to discriminate is isSignedin()
Cross doc’s sync are NOT “signed in” in coda, BUT also others could not be signed in, so we need a little more tricky passages, for example checking if user is anonymous, but at the end of the story this is the trick
So, data’s are hidden in doc A, (if you take JSON no you can still have all of them, Paul talked about this “problems” 100+ times in the community so you can just search for it), but still synced in doc B!
Did you know about this “trick” to hide datas from original table but still get them synced on the cross doc table?
Let me know down below!
Thanks for the attention :)))