I believe I found a bug in Bubble around User:converted to list:format as text
.
I’m trying to send changes to a user, so before
and now
to an external system. Problem is, every time I use User:converted to list:format as text
to format the before
and now
as JSON, I always get the now
version of the user.
I’m doing this inside a trigger, and in the User:converted to list:format as text
operation, there’s This User
, which I believe represents the current item in the list. Regardless if you are iterating over the before
or now
collection, you always get now
.
I’ve logged out the different attributes I’m interested in a Log table, and the trigger is in-fact showing a difference between before
and now
, so the issue specific to the User:converted to list:format as text
always referencing the now
version of the data.
Here’s what’s inside the User Trigger:
This results in this getting logged:
First, the “Before: Basic” is logged, then I pass the User before change
into the format as text
operation and it shows the now
values in step 2. Then in step 3 the now
value is logged “Now: Premium”.
Has anyone else observed this behavior? If so, any known workarounds?
Thank you.
In backend database trigger changes we have access to before and now, is that where you are doing this? If so does it not provide you the user now and user before change?
It does provide before and now. I logged this out. I updated my question above to show that. But when I process before and now using format as text
, it always returns the now version. Something happens inside the format as text
, even when I’m processing the before
user, it shows the now
data.
In the above image, I am logging out the before
user data in JSON format. As shown, it should be processing User before change
, however, the values that are getting logged (blurred) are all the now
values.
My guess is on the Bubble backend This User
in the “Format content as text” window is somehow getting mixed up because it’s in a trigger context.
Am I doing something wrong, or did I stumble upon a bug here?
Thank you.
I’d guess your issue is with converted to list rather than format as text. Converted to list may make it the current version.
In either case (converted to list
or format as text
), I should be able to operate on User before change
, right?
If this is a Bubble bug, are there any other ways to convert the before data to JSON before processing it externally?
Your current log won’t be JSON anyway because it will be broken. When you use format as text, it adds new line characters.
If you want to do this, I would use arbitrary text and then just use user before change’s unique ID, then user before change’s name, etc. You don’t need to use format as text to produce JSON.
3 Likes
No
When using the format as text after a list of things, it makes it easy to create one json array of those things, but when working with a single item, such as user before change, we do not need to create an array as it is not a list, we need to just create a json object as it is only one thing. To do that just use arbitrary text
1 Like
Don’t forget to always use :formatted as JSON-safe instead of quotation marks to ensure that edge cases don’t break your JSON!
1 Like
If you are looking to create a change log system that doesn’t consume a significant amount of your apps resources, my plugin Data Jedi has features and functions that can make it really cheap and efficient, where you can log every change as they happen or only once the entire thing is updated and even set up in the logs lists of what fields were changed and from which values to which.
Your current setup in the copied image below seems to use at minimum 3 actions, which if they are just api calls to your external system may not really cost much, but if those are saving to Bubble DB, that is going to be very resource intensive.
Feel free to reach out in PM to discuss how the plugin could help if you are interested.
1 Like
Highly important for long text, especially those with line breaks. Unfortunately Bubble doesn’t do this for numbers which is odd since they should. If we feed a number and it is empty, bubble doesn’t put null, it just leaves blank space, so the JSON is messed up, requiring us to use format as text after an expression to determine if the number is empty or not so as to place into the ‘no’ input area the word null
. I wish Bubble would update that so we could just use format as json safe for all json key values.
1 Like
A way I recommend is Number:formatted as number:defaulting to null
where formatted as number uses :formatted as with a decimal delimiter. Else, if a user uses a ,
delimitted decimal language, the JSON still breaks
1 Like
Thanks all for your help. Using Arbitrary Text did solve my problem. Great community! 
I still feel the converted to list
operation has a bug. Anyone know how to file a bug report with Bubble?