Conditional Logic with Validate Data

Here is my work flow:

  1. Connect to database
  2. Ensure user is logged in with appropriate permissions
  3. Retrieve API data
  4. Insert API data into database
  5. Validate before insert to ensure no duplicates
  6. Display database query with new data or old data if duplicates exist.

Problem: The work flow is being stopped by the validation when data already exists and not continuing to display the database query.

Hi,
Please try the following.

Set the same (6 Display database query) inside the else step

Thank you!

Hi @t11,

I did try that first, but the data query would never display if placed there. The condition is that if {{settlementTimeUTC}} from the API exists, do the validation and insert into the database, otherwise do nothing. {{settlementTimeUTC}} should always exist.

Just for confirmation.
Is the dipslay query inside the repeat? If yes try to drag it out. of there.

Thank you

It falls outside the repeat.

condition%202

Sorry if I am sking silly questions.
Does the query appears as a step when debugging?
Maybe by mistake the output option in the query is not checked
If data is not there, and ‘then’ step runs, you also see the display query afterwards?
Or it is never displayed

I believe there is no such thing as a silly question :slight_smile:

Query output is checked. No data is displayed because it stops at the validation step.

condition%203

Oh you validate with the ServerConnectValidator

Try the following.
Instead of validating…
1.When data is retrieved from the API
2.Run a query (for exapmple apiquery) which will be looking for the value inside yout database
3.The in the condition check 'apiquery.length<1)
4.IInside the ‘then’ step add the value from the API in the database.

By validating like this your query won’t stop if value already exists

I must have done something wrong because that did not work. Duplicate entries are being entered.

I added query2 to retrieve the data from the database and set the equal to the field from the API.

Then I added the condition as you described

like this
{{apiquery.length<1}}

Duplicates still being entered. :frowning:

What the repeat is doing? The api1.data.batchList ?

The repeat is in the server action is on the API data.

You might consider enforcing these unique values via an index on the database instead of using code. Then when it errors on the insert, you can just skip over the error on go to the next record.

Insert the query that searches for duplicate inside the repeat. Just above the condition.
Pass the value that are validating with, inside the repeat, and vlidate with it the query

I will test this more when I get off work today. Thank you @t11 and @mebeingken for your help. I’ll let you know the results.

@t11, That worked !

So everyone can see the final result, here is a screenshot of the server action.

2 Likes