Cameron Johnston
Posts: 0
Joined: Mon Jun 17, 2013 3:47 pm

Mapping multiple responses from a service to the same component

Hi,
I apologize in advance if this question has already been asked and answered elsewhere, but I couldn't seem to find any similar posts.

As part of my mobile app, I have to display three different fields provided from a mobile service. I am able to display them correctly on three different lines using three different label components. As the text from each of the fields is short, I want to display these fields next to each other on the same line, rather than on three lines. I want to save some space and make the screen more visually appealing :)

So I have two ideas, if anyone knows if I'm able to do one or the other and how that would be great:

  1. From the mobile service, map the three response fields to the same component and (probably) add JS code to create desired spacing in between.

  2. Use three labels as before, but instead of stacking them vertically, put them side-by-side. I can't seem to do this, as even when I make an existing label small enough I'm not able to drag a new label beside it.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Mapping multiple responses from a service to the same component

Map the first value directly to the component. Map the other two to a JavaScript variable. In this mapping, you can read the value of the UI component and append the new values (mapped to JS variable).

Cameron Johnston
Posts: 0
Joined: Mon Jun 17, 2013 3:47 pm

Mapping multiple responses from a service to the same component

Hi Max,

Thanks for the reply.
I'm not familiar with using JavaScript variables. Are you able to offer any more guidance on how to append the values (I'm assuming this will be done by adding JS code to the JS variable in the mapping page)? I understand that when mapping a single element to a variable and adding JS, the value passed in takes the 'value' parameter. If I understand correctly, you're saying I should map two elements to a single JS variable. As there is still only one 'value' parameter, where would I find the value of the second element being mapped to the variable?

Note that in this page of my mobile app I need to display many records, just like in the simple mobile app example provided here:
http://documentation.progress.com/out...

I believe that using a local storage variable won't work for this type of display, but I could be wrong.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Mapping multiple responses from a service to the same component

Here you go..
Image

Mapping for JavaScript variable:
Image

Cameron Johnston
Posts: 0
Joined: Mon Jun 17, 2013 3:47 pm

Mapping multiple responses from a service to the same component

Hi Max,

Thanks for the reply. I've tried using the method you've outlined above. However, the only text being displayed for each item is the value that I've mapped directly to the UI element (equivalent to value1 in your last post). It seems at each iteration, the label which the text is being read from (as in the first line of your JS code above) is different than the label which the text is being written to (as in the last line of your JS code).

In other words, what I want to happen is:

  1. Value1 gets mapped directly to UI element

  2. JS code reads from that element and completes the string, using value2

  3. JS code writes the completed string to that same UI element

  4. A new UI element is created, which will be used for the next iteration
    But instead what is happening is:

  5. Value1 gets mapped directly to UI element

  6. JS code reads from that element and completes the string, using value2

  7. JS code writes the completed string to a new UI element, leaving the first UI element with only text from value1

    I've also tried another method of not mapping anything to the UI element but instead using a local storage variable to store value1, and reading the LSV in the JS code. This didn't work either, as the LSV contains an old value each time it is read. Do you have any other suggestions or recommendations? I think the method you've already shown me could work for producing a single combined string, but I'm producing a list of many options for the user to choose from on the screen.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Mapping multiple responses from a service to the same component

Hi Cameron,

You should use service Success event. In the first parameter you will have the whole service response.

Cameron Johnston
Posts: 0
Joined: Mon Jun 17, 2013 3:47 pm

Mapping multiple responses from a service to the same component

Hi Katya,
Thanks for the reply. Can you please elaborate a bit on your answer? More specifically, when you say 'the first parameter', this is the first parameter of what?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Mapping multiple responses from a service to the same component

Hello! There is a function on service success. Parameters are transmitted to this function. All parameters which were transmitted to function you can read from pseudo array "arguments". For example first parameter transmitted to function is arguments[0]
index 0 for first element.

Cameron Johnston
Posts: 0
Joined: Mon Jun 17, 2013 3:47 pm

Mapping multiple responses from a service to the same component

Thanks for the reply Marina. I don't seem to be getting what I want in the arguments array. I've created a service success event to run the following line of JS, just to check the contents of the arguments array:
alert(arguments[0] + ' ' + arguments[1] + ' ' + arguments[2] + ' ' + arguments[3]);

The JS pop-up shows that arguments[0] contains 'object Object' and the other parameters are 'undefined'.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Mapping multiple responses from a service to the same component

Hi Cameron, it's normal that it writes 'object Object' - it is an object in which contains all service data.
If you want to see what is in this object - try this:
codealert(JSON.stringify(arguments[0]));/code

Return to “Issues”