Getting data from nested list (Web)

Getting data from nested list (Web)

  

I have a form that generates input dynamically from external API. The API return the data in the following format:

{
    "SectionList": [
        {
            "SectionName": "User Information",
            "QuestionList": [
                {
                    "QuestionName": "FirstName",
                    "InputType": "TextBox"
                },
                {
                    "QuestionName": "LastName",
                    "InputType": "TextBox"
                }
            ]
        },
        {
            "SectionName": "Event Information",
            "QuestionList": [
                {
                    "QuestionName": "Event Name",
                    "InputType": "TextBox"
                },
                {
                    "QuestionName": "Event Type",
                    "InputType": "Dropdown",
                    "DropDownList": []
                },
                {
                    "QuestionName": "Add to calendar?",
                    "InputType": "Switch"
                }
            ]
        }
    ]
}

For the structure on Outsystems side, I add additional attribute to QuestionList item to store the user's submitted value, like this:

{
    "QuestionName": "FirstName",
    "InputType": "TextBox",
    "UserAnswer": ""
},

To generate the form, I use the ListRecord to loop through SectionList, inside the list is a block that loop through QuestionList:

The issue is, when I submit the data, I am unable to fetch the UserAnswer from inside the block.

Solution I attempted:

  1. Add OnChange to input which notify the parent page to update the data.

        This method does work, but there's a significant delay (up to 2s) before the parent actually updates the data.

        Quickly submitting right after changing the input may result in the old data getting submitted.

  2. Trying to have the block get data passed by reference instead of by value

        - I tried changing the input type from list to record list, doesn't work

        - Tried to edit the structure itself but it disallow record list type

  3. Have the block expose JavaScript function with unique name (Something like "QuestionList"+RowNumber) to return UserAnswer. The submit action can loop the list and fetch data from each block.

        I managed to successfully call the function but later stuck because RunJavaScript doesn't allow output params. Similar issue when I tried to expose Screen Action instead of Javascript function.

  4. Try to have the submit action inside the block itself instead of outside. Doesn't work because API requires me to submit the entire list, and the block is only aware of single element in list.

  5. Store the data in session variable. I have the list, block and all input refer to session variable instead of widget's list variable. The data displays correctly but still won't save the modified data.

Additional information: I did the same thing on mobile, it works without problem since I can simply put list inside list, no need for a block.

Thank you,

Pasin

Hi Pasin,

A Web block data (if you remember from training) in web, are not accessible from outside it.

A possible solution is to avoid using a web block form, using a popup or modal to insert data, that is kept at the parent level (where it will be used). You than uses the web block only to SHOW the information.

Cheers.
Eduardo Jauch

Hi Eduardo,

Thank you for your reply. Due to constraints we cannot use a popup nor modal to insert data. I did workaround to avoid using web block by modifying the data into unnested list.

Regards,
Pasin