Unofficial Content

This document is part of: HowTo: Use external services

For this example lets suppose we have 4 external services provided by our main system:

getCustomersOrderedByName Returns a collection of Customers ordered alphabetically by the First Name.
getCustomersOrderedByDateOfBirth Returns a collection of Customers ordered chronlogically by the Date Of Birth.
findCustomersOrderedByName Returns a collection of Customers which meets a certain Search Criteria ordered alphabetically by the First Name.
findCustomersOrderedByDateOfBirth Returns a collection of Customers which meets a certain Search Criteria ordered chronlogically by the Date of Birth.

Note: All of this services take into consideration the pageSize and the page quantity so paging is available. To set the size of a page just set it on the rows property of the Grid.

How do we use this External Services in our SD App?

0- Create and import the WebServices to the KB.

a. Create a Panel for Smart Devices

b. Create the Variables that your Grid is going to show and design the Layout.
In this case:

vCustomerDateOfBirth -> Date
vCustomerFirstName   -> VarChar(40)
vCustomerLastName    -> VarChar(40)

ServAsDataFirstExampleLayout

c. Define the variables to consume the WebServices Previously imported to the KB.

eoFindCustomerOrdDate    
eoFindCustomerOrdName             ->Variables based on External Objects for each service imported on step 0
eoGetCustomerOrdDate           
eoGetCustomerOrdName  
sdtCustomersFindOrdDate  
sdtCustomersFindOrdName          - > Variables based on SDTs automatically generated for each service declared above.
sdtCustomersGetOrdName            
sdtCustomersGetOrdDate

d. Add the Order and Search Criteria on the Conditions Tabs.

ServAsDataFirstExampleConditions

e. Program the Load Event to consume the services depending on the interface and parameters recieved.

Event Load
if &SearchText.isEmpty() --> &SearchText is the textbox automatically generated to do searchs on SD Grids. See images bellow
  if &OrderedBy = 0   --> OrderedBy = 0 is the first order defined in step e. Se images bellow
   for &sdtCustomersGetOrdName in &eoGetCustomerOrdName.Execute(&start,&count)
    &vCustomerFirstName = &sdtCustomersGetOrdName.CustomersFirstName
    &vCustomerLastName = &sdtCustomersGetOrdName.CustomersLastName
    &vCustomerDateOfBirth = &sdtCustomersGetOrdName.CustomersDateOfBirth
    load
   endfor
  else
   if &orderedBy = 1 -->OrderedBy = 1 is the following order defined in step e.
    for &sdtCustomersGetOrdDate in &eoGetCustomerOrdDate.Execute(&start,&count)
     &vCustomerFirstName = &sdtCustomersGetOrdDate.CustomersFirstName
     &vCustomerLastName = &sdtCustomersGetOrdDate.CustomersLastName
     &vCustomerDateOfBirth = &sdtCustomersGetOrdDate.CustomersDateOfBirth
     load
    endfor
   endif
  endif
else
  if &OrderedBy = 0
   for &sdtCustomersFindOrdName in &eoFindCustomerOrdName.execute(&SearchText,&start,&count)
     &vCustomerFirstName = &sdtCustomersFindOrdName.CustomersFirstName
     &vCustomerLastName = &sdtCustomersFindOrdName.CustomersLastName
     &vCustomerDateOfBirth = &sdtCustomersFindOrdName.CustomersDateOfBirth
     load
   endfor
  else
   if &orderedBy = 1
    for &sdtCustomersFindOrdDate in &eoFindCustomerOrdDate.execute(&SearchText,&start,&count)
     &vCustomerFirstName = &sdtCustomersFindOrdDate.CustomersFirstName
     &vCustomerLastName = &sdtCustomersFindOrdDate.CustomersLastName
     &vCustomerDateOfBirth = &sdtCustomersFindOrdDate.CustomersDateOfBirth
     load
    endfor
   endif
  endif
endif
EndEvent

f. Bonus. Break By.

BreakBy is resolved by the client, so no extra service is needed. On the conditions tab enable the BreakBy option by adding a variable to it.

ServAsDataFirstExampleBreakBy

Example

serAsDataiospic1  serasdataiospic2  servasdataiospic3  
servasdataiospic4  servasdataiospic5

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant