In this step, you will extend the server module iiixEmployeeDataServer by adding a srvroutine which receives a working list and converts the list to a text file in CSV format.
The Built in Function (BIF) TRANSFORM_LIST can be used to convert a working list to a text file in various formats, such as comma separated or tab delimited. This BIF is supported on all LANSA supported server platforms and for desktop Windows applications. For web applications, the BIF must be executed on the server.
BIFs are executed using the USE command. For example:
Use Builtin(TRANSFORM_LIST) With_args() To_get()The output file name will usually be defined as the full path and file name to control where it is written.
LANSA has a number of System Variables which may be used to provide a path name which will be valid in both a development and production partition. For example, using this assignment would place the file into the Visual LANSA partition\object folder:
#Std_qsel := *part_dir_object + 'EMPLIST.CSV'
Note: The system variable *part_dir_object provides a path ending in '\'.
For example, this will resolve to: C:\Program Files (x86)\LANSA\x_win95\x_lansa\x_dem\object\ where DEM is the partition.
A Builtin Function (BIF) is a called program and the arguments it receives and returns are defined in the Repository, just like RDML commands. This enables the editor to provide detailed prompting and syntax checking for BIF parameters.
TRANSFORM_LIST - Arguments
|
1. Open the iiixEmployeeDataServer Server Module in the editor.
2. Copy and paste the working list WListEmployees and field definition EmployeeKey from the web page iiiUsingWorkingLists.
3. Create a srvroutine with the Name CreateCSV. By default the srvroutine has a default parameter of Response(*DATA) which exchanges data in JSON format. Add code based on the following:
Map for input the working list WListEmployees
Map for output the field IO$STS
Assign STD_QSEL to the value *part_dir_object plus 'WListEmployees.csv'.
Use the BIF, TRANSFORM_LIST passing list WListEmployees, STD_QSEL to receive IO$STS to produce a CSV file.
Your code should look like the following:
Srvroutine Name(CreateCSV)
List_Map For(*input) List(#WListEmployees)
Field_Map For(*output) Field(#IO$STS)
#std_qsel := *part_dir_object + 'WListEmployees.csv'
Use Builtin(transform_list) With_Args(#WListEmployees #std_qsel 'O') To_Get(#IO$STS)
Endroutine
4. Compile xEmployeeDataServer.
5. Switch to web page Using Working Lists. On the Design tab, drop a push button onto the right hand column.
Using the Layout ribbon:
a. Change Alignment to Top Left and Flow to Down
b. Change margin Left to 10 and margin Top to 40
c. On the Details tab, change Caption to Create CSV
d. Change Name to Button_CreateCSV
e. Create a Click event for the new button.
6. Create a method routine with the name CreateCSV, based on the following:
Define a component for iiixEmployeeDataServer's / CreateCSV srvroutine, name CreateCSV.
If field Listcount is greater than zero
Execute asynchronously the CreateCSV srvroutine passing list WListEmployees and field IO$STS.
Define an event routine for CreateCSV.Completed. You will complete this code in a later step.
Your code should look like the following
Mthroutine Name(CreateCSV)
Define_Com Class(#iiixEmployeeDataServer.createCSV) Name(#CreateCSV)
If (#LISTCOUNT > 0)
#CreateCSV.ExecuteAsync( #WlistEmployees #io$sts )
Endif
Evtroutine Handling(#CreateCSV.Completed)
Endroutine
Endroutine
7. Add code to the Button_CreateCSV.Click event to invoke the CreateCSV method routine.
Evtroutine Handling(#Button_CreateCSV.Click)
#COM_SELF.CreateCSV
Endroutine
8. Compile the web page.
9. Test your web page. Select a number of employees and click the Create button.
10. Use Windows Explorer to find the output text file.
Locate the path:
C:\Program Files (x86)\LANSA\X_WIN95\X_LANSA\x_dem\object
where LANSA is the installation folder name for your Visual LANSA system and DEM is your partition name.
11. Open the file WListEmployees.csv in Excel if possible or in Notepad.
12. Check the contents agree with the selected employees when the Create CSV button was clicked.