Screen Loops functionality

Hello!

I need help from this lovely community! Use case below.

I want users to be able to write articles of any sort.
Articles can be structured in many chapters.
Articles can have a minimum of 1 chapter and no maximum (infinite chapters possibility).

I’ve created an “Article Overview” screen where users can input general info. This screen has a button which is linked to a different screen “Article Details” (aka Chapter 1).
In this screen I want users to be able to click on a button to switch to Chapter 2, 3, 4…

Given that essentially it’s the same exact screen with just the chapter number changing, how can I create this kind of loop instead of creating endless screens for potentially endless chapters?

Hope it makes sense!

@SimoMTS

You want to structure it so that your Articles are a “list” of chapters.

Your button should basically create a new chapter and add it to the list of chapters in that article. You also want to add a field to the chapter called chapter number and have your list sort by that so the chapters remain in order.

@speakupboy thanks for the answer, it starts to make more sense.

Back-end DB side: I think I’ve got this right but if you can confirm it with me would be great. I have an “Article” collection and a “Chapter” collection linked with a One-to-Many relationship on the “Article_ID” field. The “Chapter” collection has also a “chapter_ID” field.
The idea is to have many chapter_IDs to one Article_ID.

Front-end side: Reading your message, I’d need to add an action to the button that creates a new chapter. The missing part is “how do I link that chapter to the same Article_ID of the previous chapter”?

@SimoMTS

When creating the chapter with the button, populate the “article” field with “current article”.

I would suggest you also need to add a field “ChapterNum” to your chapter collection as that will allow you to control the order that chapters are in. If you use the system generated Chapter_ID (which is always sequential) you wont be able to change the order of chapters or insert/replace a chapter in the middle later on.

@speakupboy me again, sorry haven’t got much time to focus on the project.

Current status:
Good: I’ve got one screen for Chapter 1 and one screen for Chapter 2. The loop between Chapter 1 and Chapter 2 works good both back-end and front-end using the Create button to also Update the ChapterNum.
Bad: The loop from Chapter 2 onwards doesn’t work at all as the button doesn’t seem to dynamically increase the ChapterNumb both front and back-end.

Any clue why?

Hi @SimoMTS,

This video might be useful for you: Adalo hints: creating several repetitive data driven screens - with just one screen in the app. - YouTube

It doesn’t answer your question directly but shows how you can display content from the database in a single screen and how you can move backwards and forward.

Best,
Victor.

That’s amazing material @Victor thanks!

Before I start to follow your steps and redo my work from scratch, the use case here is that yes the Chapter screen follows the same layout over and over BUT the values in the field are being input by users themselves.
Chapters can be infinite and I don’t know the value of Chapter fields beforehand (so I cannot populate the DB before).

Chapter fields currently are:
Title
Start Date
Days
Chapter_type

Hi @SimoMTS,

As an option, you can set a chapter numberID for a new chapter based on the existing one. In general, we have 2 cases here.
Case 1: first chapter. When the user presses a button to add a first chapter, it should create a new Chapter, with:

  • chapterID = 1
  • nextchapterID = 9999 (means this is a final one).

Case 2: adding another chapter (after the last one). Here we can add a button, then create a “single-item list” from this button. This will be a list of chapters where nextchapterID = 9999. So as a result this should be a list with 1 record visible (button), which is the last existing chapter. And for this button we can add an action to
(a) create a new chapter, with the chapterID = current chapter → chapterID + 1, and nextchapterID = 9999
(b) update a current chapter and set nextchapterID to new chapter → chapterID.

This is a very simple example, I can’t test it right now so some small details might be missing. Storing prev chapter ID is could be done similarly.

Another option is to create a linked list (using relationships), but this will be more complicated.

Best,
Victor.