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

Mapping multiple responses from a service to the same component

Thanks Illya. I've now found out that arguments[0] contains all the data from the response of my mobile service, and the other parameters in the arguments array are undefined. When I created a popup with the line of JS you've provided, the contents of arguments[0] were too big for the popup box.

For what I'm trying to do, I don't think this is a good thing. My mobile service responds with many datasets, and the number of datasets it returns changes depending on the input. I need to have a new "List Item" UI component created for every dataset that comes back from the mobile service. I have been able to do this before, but only by mapping just one of the dataset's elements to a UI component. What I'm trying to do now is combine two elements from the dataset and mapping the result to a UI component.

Hopefully this makes a bit of sense, let me know if I need to explain my situation in more detail. Thank you.

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

Mapping multiple responses from a service to the same component

Hello! Please post sample of your service responce, screenshot of screen with mapping and tell us what component are you going to use for response?

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

Mapping multiple responses from a service to the same component

Here's a screenshot of my service response. The dataset being returned contains two fields that I want to display together, short_name and name. In this screenshot, only name is being displayed (eg. Dev2 Mainroad Lower Lainland Cont). What I want is short_name and name, separated by a ' - '. For example, 'D2 MLM - Dev2 Mainroad Lower Mainland Cont.'

Image

And here's my mapping:

Image

For purposes of this issue, please disregard the entity component being mapped to InvEntityLabel, as it's irrelevant. Let me know if I can explain anything in more detail, thank you.

EDIT: I should also add that the mappings to local storage variables are irrelevant, as currently I'm not doing anything with those LSVs. Currently I'm just mapping both 'short_name' and 'name' to the text of a label. I'm using a list component with one item, and a label on top of that item. As my mobile service returns many datasets, more UI components are automatically generated - at least that's my understanding of it.

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 have a correct mapping at the moment.

If two response values refer to the same field then JavaScript code is called 2 times. The order depends on the order in which the links to field were described. That is, if input parameter "short_name" is described first and the "name" is second, then the JavaScript code will be called in that order.

Image
On the screenshot you can see mapping of two values ​​from the response.
For this mapping JavaScript code is called twice: first for the value, then for the name.

So you can create the following handler for the field:
precodevar short_name = localStorage.getItem("short_name");

if (short_name == '') { \
// we have new item, so we get short_name as first value
// next value will be Name
localStorage.setItem("short_name", value);
} else {
// we already processed short_name
$(element).text( short_name + ' - ' + value );
// next value will be short name for new item, so do cleaning
localStorage.setItem("short_name", '');
}/code/pre

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. Your logic makes perfect sense to me, and I've added your JS code to my mapping. Still, the only text that is displayed is the 'name' field, and based on a bit of debugging I've discovered that the 'short_name' field never gets transferred to the short_name variable as we expected. Instead, the short_name variable contains the 'name' field. I can understand why the other field is being transferred to the variable in the JS code, but that still doesn't explain why only the text from the 'name' field is being displayed.

As far as I can see, I haven't done anything to overwrite the text that I want to be displayed. Do you know why this is happening?

Thanks,
Cameron

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

Mapping multiple responses from a service to the same component

Hi Cameron,

Sorry, our mistake. You should create short_name variable before the call.

Replace this line
codeif (short_name == '') { //code
with the following code:
codeif ( !short_name ) {/code

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

Mapping multiple responses from a service to the same component

Hi Katya,
Replacing that line of code still produces the same result. Any other recommendations?

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

Mapping multiple responses from a service to the same component

Hello! Change code in mapping to this one:
codevar short_name = localStorage.getItem("short_name");
if (!short_name) {
// we have new item, so we get short_name as first value
// next value will be Name
localStorage.setItem("short_name", value);
return value;
} else {
// we already processed short_name
// next value will be short name for new item, so do cleaning
localStorage.setItem("short_name", '');
return short_name + ' - ' + value;
}/code

2) Before you call the service you should refresh localStorage variable short_name. To do that add the following JS for the same event you use to call the service:
codelocalStorage.setItem("short_name", '');/code
Note that this event should be before event where you call service in event's list.
But there is another way - do not map CompanyNameLabel-text. Just add JS in mapping from eCompany to CompanyListItem and add the following JS:
codeelement.find("[dsid=CompanyNameLabel]").text(value.name + ' - ' + value.short_name);/code

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

Mapping multiple responses from a service to the same component

Hi Marina,
I used the last method you've outlined, and it works! Thank you!

Cameron

Priyanka Patel
Posts: 0
Joined: Sat Aug 17, 2013 5:41 am

Mapping multiple responses from a service to the same component

Hi,
I have used the last method outlined by Marina.

element.find("[dsid=CompanyNameLabel]").text(value.name + ' - ' + value.short_name);

It was working fine few days ago, suddenly it has stopped working. I have re-created the database services and checked it by mapping just one field to a label and it works fine.

But when I try the above method, it breaks.

Has there been any updates with Appery which might have led to this problem?
Thanks

Return to “Issues”