Conditional Create vs Update Record logic eluding me

First — thanks in advance to anyone who may be able to take a look at this, and I hope to be able to be on the Helping side of this forum soon!

I have preset inputs throughout my app for users to fill out and edit at any time, and looking for any suggestions around the issues I’m running into when trying to either conditionally serve up a Create vs Update Record action, or to pre-Create the record before the user gets to the input in question.

I’ve walked through a ton of existing fabulous community member posts and similar situations that have helped narrow things down, but still no solution.

Scenario:

  • In general, it’s an education app with 10 modules.
  • Each module asks 10 self-assessment questions.
  • So each user will input up to 100 answers. These inputs are for the user’s own reference and should be viewable and editable at any time.

Database-wise, I have:

  • A Modules collection (with 10 hardcoded module records)
  • A Questions collection (with 100 hardcoded question records)
  • An Answers collection (will capture user answers for any question)
  • The Users collection

Relationships:

  • Modules is linked to Questions in a one-to-many relationship
  • Questions is linked to Answers in a one-to-many relationship
  • Answers is linked to Users in a many-to-one relationship

Desired Workflow (screenshot below):

  • The Home screen is a list of modules
  • The Modules list links to a screen with a list of that module’s Questions.
  • The Questions list links to a screen to collect the user’s question to that answer. (Currently set up as a text input and button, but also tried with form.) (Also, in a perfect world, I want the answers to show inline below each question and not require navigating to a separate screen, but just want to get anything to work.)
  • If they have not answered it yet, they can. Otherwise they can view & update their existing input.

Issue:

  • Adalo requires separate action setups to Create a record and Update a record. (I.e., there doesn’t seem to be any single action that says “create it if it doesn’t exist, or update it if it does”) and I can’t figure out any way to do the Create Record ahead of time behind the scenes, or to conditionally (also behind the scenes) link to a Create vs Edit screen depending on whether the record already exists or not for that user.

What I’ve tried:

  • I have seen a few suggestions to autocreate a Create Record behind the scenes earlier on in the process, so that by the time you get to a desired input screen, you can just do an Update.
  • If I do this on the User Signup screen, I can ensure the Create Record actions only occur once per user, but there is no way to populate the relationship between answers and their parent question in the 100 records that would need to be created for each user.
  • If I create the Answer record when linking from the Questions screen, I can set the correct parent-question-to-answer relationship, but then I am creating the record every time. I can’t figure out conditional logic to only create it when an existing record does not already exist for that user for that exact question. (Maybe there is some status I can track on the User collection but my brain melts when I try to think of what it would be.)
  • I’ve also played with redefining my database schemas and relationships but not seeing that help either.
  • I also saw this great post with a similar setup, but the video did not cover the Answer workflow (though was very impressive for other workflows!)

Any suggestions appreciated!

2 Likes

Welcome to the Community!

This is quite a lengthy post and very detailed so that helps us find a solution! What is the overall problem you are having here? I could create a clone able app for you that you can clone and see the structure of the example app.

Hey James! Thanks for the response.

So overall:

Goal - I want a user to be able to navigate to a question’s Answer Details page at any time (the third screen in my flow). From the user’s perspective, they should then be able to input an answer for the first time, and should be able to navigate back to view or update their response.

Issue - Since I can’t have one input perform both a Create and Update action, I can’t figure out how to either a) conditionally link the user to identical screens with Create or Update actions, depending on whether their Answer record already exists, or b) somehow automatically create a record, so the Answer Details page is always just an Update Record action. (That last option was a suggestion I saw in the forum, not sure if it is common/best practice.)

And maybe the right solution is in a completely different direction to achieve the goal, so any other suggestions welcome.

Hope that was a clearer explanation!

I’ll start working on a cloneable app!

That’s very thoughtful, thank you!

You could clone this app and see everything in the app! (You’ll have to create an account!)

If you want me to add any features just ask.

https://previewer.adalo.com/2d94a468-d151-405e-a304-c244b2f62dc6

Thank you so much for taking the time to do this!

My previous description of my setup may have been confusing. In each section of my app, I’m presenting the user with a list of 10 questions that I’ve created, and all they can do is answer the question, or update the existing answer to the question.

So rather than explicitly clicking Create or Edit from different screens, like in your example, I’m hoping they can click on a question from my list and just have a prompt to answer it (and behind the scenes figure out the logic of whether it’s a Create action or an Update action.)

I’ll take another pass through the example to see if I missed something. But I really like your flow for other use cases - like the modal design to edit/delete - and will use them in future!

I could help you with the rest tomorrow! :slight_smile:

1 Like

I finished updating the app to what you need it to be. (You could create the questions in the database!)
https://previewer.adalo.com/2d94a468-d151-405e-a304-c244b2f62dc6

This is great, thank you!

This helps clarify some of the conditional logic and shows me that I need to set a flag.

Where I’m still stuck is that in my scenario, I need the conditional logic to check whether or not the question has been answered by the logged-in user, not just any user. (And users shouldn’t see other users’ answers.)

BUT this definitely gotten me closer and I’ll keep playing around with the right flag to set for the visibility filters.

Thank you again for the time and detail you put into this!

1 Like

Your welcome! If you need any more help just let me know!

The community is a great place to find help!

1 Like

This is cloneable app for create and update relation for question and answer.

Hopefully, it suits your need.

Hello @andrea I see that you already got a lot of input from other members however the big thing that helped me.The way I solved it. I created a TRY Collection. Connected to a USER (the try can only belong to one user) and in you case to a MODULE (the try can only belong to one module). In the TRY Collection I also have a many to many connection to QUESTIONS, named “Questions Answered”. And a True/False property called “Try Finished?”.

Now to the tricky part. When you are in the Module View you will see one of two buttons.

  1. IF User>Try where Try Finished? is False is equal to 0. You will see a button saying “Start Try”. This button will create a Try, connect it to the module and user and send you to a Try View where you can see the unanswered questions of such try.
  2. IF user has “unfinished” trys, he or she will instead see a button saying “Continue Try”, this second button is actually a list, a list of Trys marked false in “try finished?”, in that way when you send the user to the Try View Page, it will pick up the quiz where they left.

Now If you want this options to appear for all modules in one page you will need to create this “Start Try” button + “Continue Try” button LIST and then make those two things another list of modules.

Now once you are in the TRY VIEW PAGE I have two lists.

  1. Questions to be answered: A list of Module Questions that ARE NOT in the Current TRY.
  2. Questions answered: List of questions that ARE in the CURRENT TRY.
    Just make sure when the user answers a question, it adds such question to current Try.

Hope this helps

I made this clonable app as well, hope it helps @andrea
https://previewer.adalo.com/3359c2ed-db34-4dce-abdc-c7583dfabf92

1 Like

My apologies for not being able to check this sooner as I was under a big time crunch and heads-down.

@Yongki and @ppvaldes thank you both for responding and for these detailed additional examples! They both had great components that I would definitely consider in other cases.

In my scenario, I was set on the user not explicitly “starting”/“creating” anything, but navigating to existing Informational pages that had exposed question/answer fields that could be revisited at any time.

This was what I ended up coming up with:

I moved my questions into the Modules collection, so I had Modules, Answers, and Users.
A user will have one Answer record for each module, with the answers to each question as separate fields.
Users and Modules have a many-to-many relationship.

When a module is clicked from a list, I was able to add an action to Create a new Answer record for the logged-in user ONLY IF that user was not in the Users column of that Module record. The only fields I set in the record are the Parent Module and the User.)

I then added a second action to add the user to that Module record, if not present.

— These two steps ensure that the Create Record only happens once.

The next action links to the screen with the questions/answers, at which point I’m able to do an Update Record when the user actually answers the questions.

I’ll attach a clonable example for anyone who may be interested and to clarify my fast update above. It may be a little over-engineered but was the only way I found to match my design for V1…

Thank you both again!

Hi @andrea ,

Glad that it is working out.

Indeed, database design plays vital role for UI and UX.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.