HowTo: External Services (Scenario2)

Unofficial Content

This document is part of: HowTo: Using external services in a Smart Device App

For the second example the following service are going to be used:

findCustomersByFirstName Given a search criteria returns a collection of Customers which satisfy the condition. Searching only by the first name
findCustomerByLastName Given a search criteria returns a collection of Customers which satisfy the condition. Searching only by the last name
findCustomersOrderedByName Given a search criteria returns a collection of Customers which satisfy the condition. Searching by the first name and last name
filterCustomersByBirthDate Given a range of dates, returns a collection of Customers which Birth Date in the range.

Steps a & b are the same as Example 1.

c- Create and program the procedure that is going to do the mapping between the Smart Device Grid and the services.

Parm:

parm(in: &orderedBy, in: &SearchText, in:&searchField, in: &cvCustomersDateOfBirthFrom, in:&cvCustomersDateOfBirthTo, in: &start, in: &count, out:&sdtCustomerscol);

Variables:

count
cvCustomersDateOfBirthFrom
cvCustomersDateOfBirthTo
orderedBy
sdtCustomers
sdtCustomersCol
sdtCustomersFilter
sdtCustomersSearchByFirstName
sdtCustomersSearchByLastName
searchField
SearchText
start

Source:

if &SearchText.IsEmpty()
for &sdtCustomersFilter in &eoFilterCustomersByBDate.Execute(&cvCustomersDateOfBirthFrom,&cvCustomersDateOfBirthTo,&start, &count)
  &sdtCustomers = new()
  &sdtCustomers.CustomersDateOfBirth = &sdtCustomersFilter.CustomersDateOfBirth
  &sdtCustomers.CustomersFirstName = &sdtCustomersFilter.CustomersFirstName
  &sdtCustomers.CustomersLastName = &sdtCustomersFilter.CustomersLastName
  &sdtCustomersCol.add(&sdtCustomers)
endfor
else
if &searchField = 1  --> &searchField = 1 is &vCustomersFirstName (see the above image of the conditions tab)
  for &sdtCustomersSearchByFirstName in &eoFindCustomersByFirstName.Execute(&SearchText,&start,&count)
   &sdtCustomers = new()
   &sdtCustomers.CustomersDateOfBirth = &sdtCustomersSearchByFirstName.CustomersDateOfBirth
   &sdtCustomers.CustomersFirstName = &sdtCustomersSearchByFirstName.CustomersFirstName
   &sdtCustomers.CustomersLastName = &sdtCustomersSearchByFirstName.CustomersLastName
   &sdtCustomersCol.add(&sdtCustomers)
  endfor
else
  if &searchField = 2 -->&searchField = 2 is &vCustomersLastName (the second variable defined on the condtions tab)
   for &sdtCustomersSearchByLastName in &eoFindCustomerByLastName.Execute(&SearchText,&start,&count)
    &sdtCustomers = new()
    &sdtCustomers.CustomersDateOfBirth = &sdtCustomersSearchByLastName.CustomersDateOfBirth
    &sdtCustomers.CustomersFirstName = &sdtCustomersSearchByLastName.CustomersFirstName
    &sdtCustomers.CustomersLastName = &sdtCustomersSearchByLastName.CustomersLastName
    &sdtCustomersCol.add(&sdtCustomers)
   endfor
  else   --> &searchfield = 0 means any of the search conditions
   for &sdtCustomersSearch in &eoFindCustomerOrderedByName.Execute(&SearchText,&start,&count)
    &sdtCustomers = new()
    &sdtCustomers.CustomersDateOfBirth = &sdtCustomersSearch.CustomersDateOfBirth
    &sdtCustomers.CustomersFirstName = &sdtCustomersSearch.CustomersFirstName
    &sdtCustomers.CustomersLastName = &sdtCustomersSearch.CustomersLastName
    &sdtCustomersCol.add(&sdtCustomers)
   endfor
  endif
 
endif
endif

Note: The code in blue is because for the purpose of this example we wanted only 1 out parameter, so we choose one of the SDTs that was created to use is to be the out parameter of the proc. So no matter which service it was invoekd it had to "transform" it to a neutral SDT.

d. Set the conditions tabs with search node with the Option for individual field property set on true. Also Advanced Filters by &vCustomersDateOfBirth with range property = true

servasdataexample2conditions

e. Do the Load Event of the panel created on the a step a to load the UI with the information.

Event Load
for &sdtCustomers in proxyServicesAsData(&orderedBy, &SearchText,&SearchField,&cvCustomerDateOfBirthFrom, &cvCustomerDateOfBirthTo, &Start, &Count)
  &vCustomerDateOfBirth = &sdtCustomers.CustomersDateOfBirth
  &vCustomerFirstName = &sdtCustomers.CustomersFirstName
  &vCustomerLastName = &sdtCustomers.CustomersLastName
  load
endfor
EndEvent

f. Examples

servasdataexample2androidnormal

Filters->

servasdatafilters1  servasdatafilters2  servasdatafilters3

Search By Field ->

servasdatasearchfield1  servasdatasearchfield2  servasdatasearchfieldall