Anthony Berko
Posts: 0
Joined: Thu Oct 23, 2014 9:04 am

Loop a REST weather service through list

Hi guys

I have read through some similar posts but cannot find an answer that works. Im hoping its an easy fix this one but here goes.

I have a weather service using Wunderground weather API. Unfortunately they can only return a single weather location per query. What I have is a list that I will be changing every week and I would like the service to loop through that list of locations and return the weather at a glance in the list.

I can get it to work for a single list item perfectly. But if I populate a list of locations the service does not return any weather not even for the first item in the list.

Here is what is looks like with 1 item

Image

If i then map the list to load all locations..

Image

It will list all locations from my database..

Image

Now that the mobilelistitem_9 is successfully loaded I need something to run the REST service for the first item in list "Australia/Sydney" and return the weather in a grid for that item and do this for each location.

Could you please provide me with any help as to what code I could use for this loop.

Thanks Anthony

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Loop a REST weather service through list

Hello Anthony,

Please clarify the question. What is the difference between mapping of the only one item and list items?

Anthony Berko
Posts: 0
Joined: Thu Oct 23, 2014 9:04 am

Loop a REST weather service through list

Hi Sergiy

If I map only one list item a weather REST service successfully takes the value of a label box in the list item and queries a weather API and returns the weather results to the same list item. If you see the first image I posted it shows this.

However if I map all list items, the REST service appears to do nothing on completion of the list being populated. If you look at the 3rd image I posted you can see the complete list but no weather information is returned (not even the first list item).

It appears that there is no way I can have the weather REST service run for each list item as the list is being populated.. So Im hoping there is a way I can run a loop after the list is displayed that will iterate through each list item and get the value of the label box in the list item and pass it to the query in the weather REST service and then the service will return weather for that location in the list item to a grid in the same list item. The loop will have to so this for each item in the list.

I realise this loop will be slow on the app but thats ok.

If you come up with some code here is the names of the list, label, service and grid.
list -> mobilelistitem_9
label for weather query -> lookupValue
REST service for API -> GetWeatherInList
Grid in list item for weather -> WxGridTest

Hope this makes sense?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Loop a REST weather service through list

You are right, it is better to run these services in the loop and write their responses to the storage variables, which you can use in the mapping after that.
Please look at this example how to run services in the JavaScript: https://devcenter.appery.io/documenta...
and how to save service's response to the storage variable: https://devcenter.appery.io/documenta...

Return to “Issues”