Create a new thing only when

Hi, guys!

Trying to figure out how to create a new row in datatype “all players”, if the name in a submitted report does not exist already in the database.

E.g, if the name of the player in the report does not already exist in “all players”.

And, if the name of the player does exist in the database, is there any way to merge the existing row of data with the newly submitted data, so i can keep all reports linked to one player?

Thanks in advance :slight_smile:

Hey! Sure, no problem at all.

Under the create a player workflow step, you’ll want to add a condition (like you’re alluding to) which does a search for players (with constraints player_name = input player_name): count is 0.

That way, if the count of players with the same name is 0, it will create a new one.

Then you can add a new workflow step, which is to change a player. Similar to the create a player step, you’ll add the same condition. Rather than using :count is 0, you’ll use :count > 0.

For the thing to change, you can use the same search, but instead of :count is 0, you’ll want to use :first item.

This will get you the result you are looking for. However, there are better ways to do this for performance purposes. You can research best practices if you think this flow will be slow as your player database grows.

Another thing to consider is if you’ll have multiple players with the same name in the future. For example, chances are pretty decent that if your app grows, you’ll have at least two players named Sam Smith. If/when that happens, there could be some issues with this setup…

1 Like

Wow, amazing @mac2 !

The solution worked, and created a new player through the workflow adjustments you suggested:

When it comes to changing a player- do I add this as a step 5? Like this:

Thanks again, first week diving into this… :slight_smile:

1 Like

Hi, to make changes to a player, you can use the “make changes to a thing” action instead of “create a thing”

It’ll ask for what thing you’d like to change, and you can then “do a search for” that player and filter his name out like you have for the conditional on step 4 :heavy_check_mark:

As mentioned by @mac2 there’s better ways to do this for performance and reliability reasons, but just to get the hang of things, it works :slight_smile:

2 Likes

Thanks a lot @taylor1 :relaxed:

As a rookie-bubbler I do not expect my set up to be perfect, but I’m eager to learn this- the most effective and smooth way for existing/future projects.

Can you guys please point me in the direction of where I can do some research on best practices on workflows and databases, where add/change/update data fields in the database is reviewed?

Thanx again good people :fire:

One of the most important things to learn as a Bubble dev (and any software developer for that matter) is how to search the forum :crazy_face:

Some excellent posts go back 5+ years on best practices. Bonus tip: @petter is the king of this—check out his work.

3 Likes

totally unrelated: Does anyone ever get nostalgia, looking back at their first project or app in bubble, trying to figure everything out? I remember being in awe of what could be built at such speeds.

2 Likes

Absolutely. Nostalgia and embarrasment.

Lol, i figured this out and now i feel sooo stupid :rofl: