Forum Academy Marketplace Showcase Pricing Features

How to determin if I ADD or UPDATE database records

Hi Guys,
I am looking for pointers on how to do something. I have an empty database with fields SKU & QTY.

I need to know how to add a record to the database if it doesnt exist, but once it exists I want to update the QTY so if someone puts SKU=abc, QTY=10 it would write that information to the database, if they then did SKU=abc, QTY=5, the result in the database would be SKU=abc, QTY=15.

Just not sure how to determine if I need to ADD or UPDATE

If :is empty add otherwise update

1 Like

Create duplicate workflows, each with it’s own conditional statement.

I am not sure how to do IF/ELSE statements or duplicate workflows

It depends on how you want to do it, I do it 2 different ways but the main way;

I usually have a group where the data type is that group’s thing, so when someone hit’s save, if that group is empty;

Then we create a new thing. If it’s not empty, we update what is there.

This is the Flow of things

1 Creates it when it’s empty, 2 updates if it isn’t.

Alternatively, you could have 2 different workflows with the actions based on the conditions;
image

For me, it just makes the page less cluttered when it all falls under 1 workflow, but everyone does it differently I’m sure.

1 Like

I’ve had bugs before where certain workflows were running too fast and it would skip certain conditional statements or ignore them. If you run two different workflows, put them into one folder, it won’t be cluttered.

Two different workflows are also easier to maintain when you need to make changes to the flow and actions following that particular workfow.

1 Like

This is true, I have experienced odd things happening on data intense workflows, usually if I have more than 10 fields to update I separate the workflows to be sure the correct thing happens as it should.

So separating the workflows with conditions is definitely the route to go

1 Like

So am I correct in thinking that it accesses the database twice.
1st Pass the record isnt there so it adds it, but on the 2nd pass it is there so it updates it. If I have the “right end of the stick”, wouldnt it be better trying the update first then the create

Yes that’s correct, after taking the screen shots I reversed the flow as that makes more sense.