11
Views
7
Comments
Solved
Answer a question from the lists fetched from database
Question

Hello!
I have this scenario,
Lists of questions fetch from database and displays using List widget. I have to answer it one by one. My question is, how can I handle the answers from each question since I am displaying it with a list widget. Everytime I am answering one question it goes the same with another questions. I am not sure if I explained it correctly, but please see clip attached for reference. I understand this is happening because I am only using the same variable for the answers, so what do you suggest to use for this kind of scenario? 
Thank you in advance.

Untitled video.mp4
2024-12-02 13-16-47
Vipin Yadav
Solution

Hi RD, 

I have made changes to your oml file. Please check it. 

Thanks,

Vipin Yadav

CS_RDMportfolio.oml
2024-12-02 13-16-47
Vipin Yadav

Hi @RD.,

I watched your clip and noticed that you are using local variables to bind your textbox and other controls, which is why the same value appears in all controls. A better approach would be to bind each control to a list of structured data. This way, each control displays its respective value. 

Could you please share your .oml file? I can then make the changes and show you how it's done. 

Thanks,

Vipin Yadav


UserImage.jpg
RD.

Hello @Vipin Yadav , thanks for your response. Yes, exactly, I am using same variables for the answers within the list and that is where I am having the issues. I am not sure if I can share the oml but I'll try to duplicate it to my personal environment to be more specific.

UserImage.jpg
RD.

Hello @Vipin Yadav , please see attached .oml for reference. Thanks.

CS_RDMportfolio.oml
2024-12-02 13-16-47
Vipin Yadav
Solution

Hi RD, 

I have made changes to your oml file. Please check it. 

Thanks,

Vipin Yadav

CS_RDMportfolio.oml
UserImage.jpg
RD.
2025-08-07 06-30-56
Amit J
Champion

Hi 

It seems like the issue you're facing is that all questions are sharing the same answer variable, so when you update one answer, it reflects on all the other questions. To resolve this issue, you need a way to store the answers for each question separately. Here’s how you can handle this scenario in OutSystems:

Solution:

You can use a List of structures to store the answers for each question separately. Here's a step-by-step approach to implement this:

  1. Create a Structure:

    • Create a new structure called QuestionAnswer with the following attributes:
      • QuestionId (Integer or whatever your primary key is for the question)
      • Answer (Text or whatever the answer type is)
  2. Create a List of QuestionAnswer:

    • Create a local variable (or session variable) that holds a List of QuestionAnswer. This list will store the answers for each question.
  3. Binding the Answers to Each Question:

    • When you're displaying the questions in the List widget, you can bind the answers to each question individually by using the QuestionId.
    • In your List widget, for each question, retrieve the corresponding answer from the list of QuestionAnswer based on the QuestionId.
  4. Updating the Answer:

    • When the user submits an answer, update the corresponding entry in the list based on the QuestionId. This ensures each question has its own answer.

      Example:
      1. Structure Definition:

        • QuestionAnswer Structure:
          • QuestionId (Integer)
          • Answer (Text)
      2. Local Variable:

        • Create a local variable QuestionAnswersList of type List of QuestionAnswer to store the answers.
      3. Display Answers:

        • For each question in the List widget, you can use an If condition or an aggregate to check if the QuestionId already exists in QuestionAnswersList and retrieve the answer for that specific question.
      4. Submit Answer:

        • When a user answers a question, use an action to find the corresponding QuestionAnswer in the list and update the Answer value. You can use ListAppend or ListUpdate to modify the list.


          This way, each question will have its own answer stored independently, and updating one question’s answer won’t affect the others.Let me know if this helps or if you'd like more specific guidance!
UserImage.jpg
RD.

Hello @Amit Jain , I believe this will also work, and I can use this idea for the future tasks. Thank you!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.