Question T22554
Visible to All Users

Using User Input to Query DynamoDB Based on First Four Characters

created 12 days ago

The user enters an input, such as 'abc', and I need to use this input in the backend for further operations. The use case is as follows: The user will enter the first four characters in an input field, and we will use these four characters to query DynamoDB. Based on a filter operation, we will retrieve the response matching the provided input. This is urgent as I need to give a demo to the client.

Comments (1)

    json content:

    {
    "type": "paneldynamic",
    "name": "business_application_data",
    "title": "Business Application",
    "isRequired": true,
    "templateElements": [
    {
    "type": "dropdown",
    "name": "application_name",
    "title": "Business Application Name",
    "isRequired": true,
    "choicesByUrl": {
    "url": "https://10.139.xxx.xx/api/v3/cmp/inboundWebHooks/IWH-lolv712y/run/?token=5IBJylO5MQdWrJV-rTRQDXuEdJUZ5cN5DEHcbszc0-g&param=application_name",
    "path": "options",
    "valueName": "id",
    "titleName": "name",
    "allowEmptyResponse": true
    }
    },

    Answers approved by surveyjs Support

    created 12 days ago (modified 12 days ago)

    Hello,
    To achieve this usage scenario, enable the lazy loading for your Dropdown question and send a request to fetch choices using the SurveyModel.onChoicesLazyLoad function. For more information, please refer to the following demo: Lazy Loading.

    Should you have any further questions, please feel free to contact us at any time.

      Show previous comments (1)
        JSON
        { "type": "paneldynamic", "name": "business_application_data", "title": "Business Application", "isRequired": true, "templateElements": [ { "type": "text", "name": "application_name", "title": "Business Application Name", "isRequired": true, "validators": [ { "type": "regex", "text": "The form is invalid. It must accept exactly 4 characters", "regex": "^.{4}$" } ], "placeholder": "exactly 4 character only" },
          1. The user enters a four-character input, e.g., "abcd."

          2. Based on the input, a query is executed in DynamoDB to fetch matching records (one or more).

            • If exactly one record is found, its value is displayed in a dropdown.

            • If multiple records are found, all matching values are listed in the dropdown.

          3. The user can then select their desired value from the dropdown.

          I am using single input field for all the above operation.

          Here is the json file:

          JSON
          { "type": "paneldynamic", "name": "business_application_data", "title": "Business Application", "isRequired": true, "templateElements": [ { "type": "text", "name": "application_name", "title": "Business Application Name", "isRequired": true, "validators": [ { "type": "regex", "text": "The form is invalid. It must accept exactly 4 characters", "regex": "^.{4}$" } ], "placeholder": "exactly 4 character only" },

          and attached video fo your ref.

          can you share the sample json for the above steps…

            Hello Ajit,
            Thank you for the update. A single-input field allows users to enter a value. It doesn't allow users to select a value from a drop-down list.
            To achieve your goal, please try the lazy loading option. The lazy loading is a feature implemented specifically for Dropdown and TagBox question types. It doesn't actually mean that choices will load longer. The lazy loading feature allows you to perform a call to your server-side endpoint as soon as a respondent enters some text within an input box.

            With the lazy loading option, respondents enter some filter string within an input box; at this point, a survey raises the onChoicesLazyLoad. Within the onChoicesLazyLoad function, you can obtain a search query, perform a call to your server-side API endpoint, fetch data and return this data to the Dropdown. A dropdown will display choices which you return from your endpoint.

            If your endpoint returns a single or multiple items, they will appear in a dropdown and users will be able to select a required item.

            Please refer to the above demo. Let me know if you require any further assistance.