How to save data from a repeating group for each row?

Hi All.

I am attempting to save the results fro a repeating group to the database.

  • I have a repeating group which shows questions, inside this I have another repeating group which shows answer options as buttons 1, 2, 3, 4, 5.
  • The user select an answer for each question as shown in the image below.
  • I have it all working but new trying to save the result and using an API but really struggling to figure out how to save the result selected.

I have an API set up but unable to get the API to create a new record row for each answer selected in the repeating group.

I have a feeling that I need to make the API a list/ array and add the data from each question to a custom state, but not sure how then to use this to create a new record row for each question answer using the API, or is this incorrect?

Can anyone point me in the right direction.

How do I save each of the answers from the repeating group into a new row record in the database?

I have a quiz app, and the way I do it is when the user signs up (or starts the quiz), I run an API workflow where I add a copy of every question to the user. Then, when the user makes an answer choice, I just update that user’s specific to include their answer.

1 Like

Thanks!

This doesn’t work in my case as the answers are created in an answer table linked to the user. It seems the issue I have is that when using the next question button to create the workflow to add the records for each answer, I can not access the inner repeating groups cells data where I have a custom state on the repeating group to store the answer for each question. Its frustrating I can only access either a custom state in a parent or child.

Is there any way to store the data in a custom state several parents up or children down?

Cheers

Steven

Hi @StevenM,

Put the inner repeating group inside a group so that the hierarchy of elements is:

/ RG of Questions
// Group
/// RG of Answer Options

Set the content type of the Group to the Question data type (i.e. the same type as RG Questions) and set the data source of the group to Current Cell’s Question.

Now, whenever an Answer Option button is clicked, you can reference this group element’s Question.

If the new Thing you’re ultimately trying to create is a Response…

Response
Question (Question)
Answer (Answer)
Created By (built in User field)

… Then when the button is clicked: Create a new Response:

Question = Group’s Question
Answer = Current Cell’s Answer

Notice that this doesn’t need to involve an API and can happen directly in the workflows on the page. For the user to change their answer, you’ll want to have a “Make a Change” action available only when a Response already exists for this question and User. Naturally, the Create a New Response action should only happen if it doesn’t exist.

The whole key here is that group!

EDIT: Having the list of responses get saved from that single Next button is tricky because you need a “data set” of Answer + Question, which you can’t do in a custom state like you can with a database records. It’s easier to manage by create/edit records off each Answer click.

Hope this helps!

3 Likes

Thanks Gaby!

This helped me try a few things but it didn’t work completely because the set-up is a little more complex. But figured out how to create an API workflow for each button selection which works like a dream and pulls in info from all the different areas. I had to use the API option on button selection because the survey part of the app has a complex database structure, designed to allow for complex survey questions and just could not get it to work.

When I set it up using the API I was able to use the API workflow across all questions. I suspect the reason that it would not work was because of the relationships between the groups and the repeating groups.

It seems to be a limitation on how your able to reference groups within groups to get to the data.

But at the end of the day it works and is super fast.

I have types:
Survey
Questions
Question Options
Question rating options
Question types
Question Answers

An update to the solution.

Even though the API method was working like a dream it was also using a great deal of the app resources and I actually hit capacity while testing.

With a bit more hair pulling and strong coffee I finally worked out how to do it within the standard work-flow. However, on selecting each button there is a slight delay while the app submits the answers, you can see the progress bar working.

It’s only a second but enough to be annoying to the user. The API method was seamless but was causing the app to hit capacity in testing.

Any ideas and suggestions would help?

Can I turn off the progress bar at the top of the screen?

Cheers

Steven

An update to this thread as it may help others.

I have found that if you include a search in a work-flow to save data it uses a lot of your allocated account resources!

But if you load data on page load and through actions (something happening on the page) to put data into the Custom States on the page and then save from those custom states to your database (rather than a query) it reduces the resources that your acocunt uses.

Also if you have nested repeating group elements and you cannot do without searches, it is better to structure these in the way that not all of them are repeated each time the most inner cell is evaluated, but you store them in custom states, for example, and are calculated only once or at least in an outer repeating group.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.