Need advice for DB trigger

Hello,
I’m stuck on something relatively simple but my brain has been looping on it for way too long, so I need some help. :blush:

I have a data type called “report,” which contains a list of users and several other fields. I don’t want my database trigger to activate when this list of users is modified (regardless of whether users are added, removed, or otherwise updated). I only want the trigger to activate for changes to the other fields (this part is already managed).

What’s the simplest and cleanest way to handle this? I’ve tested several approaches, but it’s not as straightforward as it seems.

Do I absolutely need to rely on intersections and 12-line expressions? Isn’t there a simpler and more maintainable solution? Thanks!

You want a database trigger when changes are made to other fields on the report datatype except the list of user’s field, right?

what is your current working setup (“intersections and 12-line expressions”)?

Thanks for your reply.
Right now i have this :

rapport now's statut is not a renseigner and rapport before change is not empty and rapport now is not empty

Which works well !
But when someone modify the list of users (add, remove, modify) then the DB trigger is trigerred and i do not want this.
How can i do this ? Just one thing : i do not want to modify the WF and only work with the db trigger.
Thanks !

I use a similar technique on creating activity feeds when data is changed…if your database trigger has that ‘only when’ from your screenshot, it’ll only run when that condition is met.

This is mine for running a trigger only when a new record is created:

So if any other field is just modified, this trigger won’t run. For yours, a simple soluion might be comparing the count of users on ‘record.now’ vs ‘record.beforechange’.

That will obviously only work in the cases where users are added are removed. The other way would be to convert the list of users into a string of their unique id’s and compare those strings. If different, trigger away…

Thanks for your reply - I thought about your solution “count of users on ‘record.now’ vs ‘record.beforechange’” but lets imagine we only modify the name of the users, then it doe snot work ! or am i missing something ?

correct, using ‘count’ only would be limited. You’d have to use my other suggestion, that is, convert the list of users to a string: uniqueid-firstname-lastname or something and then compare the ‘now’ and ‘before’ strings. If they’re the same, names haven’t changed. If their different, a name has been changed.

@Alter345 You might share an image for better idea of what your expressions look like.

I think you need to change your expressions to something like “report before change field1 is not report now field1 or report before change field2 is not report now field2…etc”. As long as you do not mention the list of user’s field, it will not call that database trigger.

Bubble manual says this " Database trigger events look at any change to a data type, and triggers the event if one takes place. Bubble then checks the Only when expression and stops the rest of the workflow from running if it returns a negative value (no )."

so your only when expression is the solution here, even though it mean you will have to list all the fields you will like the database trigger event to watch over.

Right now i have this see attached

We are comapring a list, i cannot use “is” @iwakinomotoye , that’s the point

i will investigate this thanks !

oh, and odds are if names are changing the character count in the name will be different so checkout the ‘number-of-characters’ method. Instead of doing a regex, just compare the length of that string, or the count of the characters.

Wow that sounds like an overcomplicated system ^^

Okay, sorry I didnt catch the problem initially. This should work:
Report before change field1 intersect with Report now field1:count is report now field1:count @Alter345

Thanks. But in the case as said above if we modify a user then your expression will not work right ?

well, it is complicated. if you want to see if a list of names have been changed, you’re going to have to compare the strings. The only other thing that might work is trying something like “only when userlist.before is not userlist.now” and hope bubble does the comparison for you.

understood thanks

you’d want to be very careful with “database trigger”

  1. it is evaluated each time a record changes. If you use autobinding then that can be extremely often.
  2. If the condition is heavy then it’ll amplify the WU (frequency X complexity)

In most cases you are better using an api workflow that is triggered once at the relevant points in the logic (report save)

If you only want to trigger it for certain fields from the front end then you can still do that by temporarily storing original values and comparing them to new values. States are best for this and that is handled client side so no WU cost.

Noted and thank you for your help