How to map JSON response as suggestions

  • Fulya
        vor 3 Jahren #24392

        Hi everyone,

        I have a problem and I hope someone here can help me.

        I am getting the following JSON response back from a connector call:
        {
        “streets”: [
        “Ehrenbergstr.”,
        “Ehrenfelder Platz”,
        “Ehrenfelder Str.”,
        “Ehrenfelsstr.”
        “Ehrenpfortensteig”,
        “Ehrenpreisweg”
        ]
        }

        The individual streets shown here are to be displayed as a suggestion when “Ehre” is entered in my street input field.

        I have already tried a lot of things, but have not been able to get the mapping right so far. For example, I have already saved the response as a collection and done the following:
        – set suggestionRowsTemplate to true
        – assigned my collection to suggestionRows (first tried in Designer. But then I also tried to pass the JSON output from my connector call to suggestionRows).

        I hope someone here can tell me how to do the mapping. An exact step-by-step guide would be great, because I really tried a lot of things and nothing worked.

         

         

        Armin Winkler
            Has successfully completed the online course Introduction
            Has successfully completed the online course Intermediate (200)
            Has successfully completed the online course Advanced (300)
            Has successfully completed the online course Basics (100)
          vor 3 Jahren #24426
          Up
          1
          Down
          ::

          Hi Fulya,

           

          I created a small example application for your use case which you can download from here and then import into your instance: https://files.simplifier.io/f/6bce84879ee346eeb72b/?dl=1 . To download the file, you need to enter the password “simplifier”. Please take note that the download link will only be valid for 30 days.

          In the application I added a sap.m.Input widget to a screen and added a ui.core.Item to the suggestionItems aggregation of the sap.m.Input. The ui.core.Item serves as a template which will be copied as often as there are elements returned from your data source which are bound to the suggestionItems aggregation. My data source in this case is a server-side business object (BO) which returns the whole JSON that you provided. What I’m doing to make sure that the output is in the correct format is that I’m directly returning the array holding the possible values for the street name under the parameter name “suggestions” by navigating to the streets field within the JSON. Please look up the parameter name field in the output parameter panel of the business object function “getSuggestions” as reference. With doing so, I can directly map the outputted collection of the BO and its included structure onto the aggregation and its template item in the Process Designer. Of course I had to configure my sap.m.Input widget in the Designer first, what I did was the following steps:

           

          – set suggestionItemsTemplate to true

          – selected the collection data type that is configured in the BO for the suggestionItems aggregation

          – set showSuggestion to true

           

          Now, when running the application, the BO is called on start and the JSON output mapped onto the suggestionItems aggregation. If I input “Ehre”, it will display the matching results in a popup on top of the sap.m.Input.

           

          Hope this helps you! Please let me know if there’s any questions left.

           

          Regards,

          Armin

           

          Edit: I forgot to tell you, why I didn’t use the suggestionRows aggregation but suggestionItems instead: As you can read here https://sapui5.hana.ondemand.com/#/api/sap.m.Input%23aggregations suggestionRows is best used when you want to display suggestions in a tabular manner. I don’t think this would fit your use case though since you only have one specified value that you want to display per entry. Thus suggestionsItems is the appropriate solution.

          Fulya
              vor 3 Jahren #24470
              Up
              0
              Down
              ::

              Hi Armin,

              this was exactly what I was looking for. Worked perfectly! Thank you very much!

              Best regards,
              Fulya

            Ansicht von 3 Beiträgen – 1 bis 3 (von insgesamt 3)

            You must be logged in to reply to this topic.