A useful feature of using field maps in screen definitions is that they can be used to automatically generate HTML reports and forms. This topic will show how this can be achieved.
There is a requirement for a screen definition file to have already been created. This example will use the definition file that is installed with Flynet Viewer, namely: Insure.xml
Refer to Screen Transitions and Navigation for information about how to handle navigation.
Create a new file in the "Inetpub\wwwroot" folder called "MapGen.asp".
Copy the code below into the file and open it in a browser (http://localhost/MapGen.asp). A list of screens, followed by field labels and textboxes should appear in the browser.
Note that this example is traditional ASP not ASP.NET
<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE>USE MAP META DATA To CREATE HTML FORMS</TITLE>
</HEAD>
<BODY>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Connect to the host, navigate to AcctUpdate,
' and generate the HTML form.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim objCon 'Connection object
Dim objScr 'Screen object
Set objCon = server.CreateObject("FLYSCREEN.HostConnection")
'try to logon
connect
If objCon.connected Then
navigateTo
disconnect
Else
Response.Write "Connect to host failed!"
End If
%>
</BODY>
</HTML>
<%
'Connect to the host
Sub connect
objCon.hostName = "Insure" 'set to match the hostname settings in admin console
objCon.connect "standard"
session("sessionkey") = objCon.sessionKey
End Sub
'Disconnect from the host
Sub disconnect
objCon.disconnect "stop"
session("sessionkey") = ""
Session.Abandon
End Sub
'Navigate to the AcctUpdate screen
Sub navigateTo
Dim strScrName 'Name of screen
Dim strLast 'Name of last screen
Dim count 'Avoid infinite loop in navigation
Set objScr = objCon.getScreen
count = 0
strScrName = objScr.getScreenName()
strLast = strScrName
Response.Write "Screen: " & strScrName & "<BR>"
Do Until strScrName="AcctUpdate" Or count > 10
Select Case strScrName
Case "Start"
objScr.mappedSet "Username", "simmy"
objScr.putCommand "[enter]", 2000
objScr.waitForScreen "SysSelect", 60000
Case "SysSelect"
objScr.mappedSet "Selection", "2"
objScr.putCommand "[enter]", 2000
Case "Signon"
objScr.mappedSet "Userid", "simmy"
objScr.mappedSet "Password", "host"
objScr.putCommand "[enter]", 2000
Case "SignonComplete"
objScr.putCommand "[esc]", 2000
Case "MyClearScreen" 'A special screen - refer to definitions help
objScr.putKeys "info"
objScr.putCommand "[enter]", 2000
Case "PolicySelect"
objScr.mappedSet "Company", "50"
objScr.mappedSet "AccountOrPolicy", "12345678"
objScr.mappedSet "Select", "2"
objScr.putCommand "[enter]", 2000
End Select
'The code commented out below would be a neater way to check that we are
'on a different screen but VBScript's error handling is not great to
'catch thrown errors, so we will check manually that the screen name has changed.
'wait for any screen that is not the last one
' strScrName = objScr.waitForScreen('*!, [error Not on a different screen]', 2000)
count = count + 1
strScrName = objScr.getScreenName()
If strLast = strScrName Then
Response.Write "<H2>Still on the same screen! Halting execution!</H2>"
Exit Do
End If
Response.Write "Screen: " & strScrName & "<BR>"
Loop
If strScrName="AcctUpdate" Then
displayUpdateForm
Else
Response.Write "<H3>Navigation to AcctUpdate screen failed!</H3>"
End If
End Sub
'
'Use the map meta data to generate the HTML form
Sub displayUpdateForm
Dim objCurrentDef 'ScreenDef object
Set objCurrentDef = objScr.getScreenDef 'get the current definition
If objCurrentDef.mapCount>0 Then
Set objMap = objCurrentDef.getScreenMap(CLng(0)) 'get the map by index (force conversion to long)
%>
<FORM NAME="frmAcctUpdate">
<Input Type="hidden" NAME="action" VALUE="update">
<TABLE>
<%
For i = 0 To objMap.fieldCount-1
Set objMapField = objMap.getMapField(CLng(i))
Response.Write "<TD>" & objMapField.name & ":</TD>" _
& "<TD><INPUT TYPE='text' NAME='" & objMapField.name _
& "' VALUE='" & objScr.mappedGet(objMapField.name) _
& "' SIZE='" & objMapField.length _
& "' MAXLENGTH='" & objMapField.length & "'></TD></TR>"
Next
%>
</TR></TABLE>
</FORM>
<%
Else
Response.Write "<H3>No maps loaded. Ensure that the DefinitionsList" _
& " registry entry has Insure.xml as an entry.</H3>"
End If
End Sub
%>
The code above has four subroutines/functions:
1. | connect |
2. | disconnect |
3. | navigateTo |
4. | displayUpdateForm |
The connect and disconnect are self-explanatory. The navigateTo handles the navigation to the "AcctUpdate" screen.
If the navigation ends up on the correct screen ("AcctUpdate") then the displayUpdateForm routine is executed. It begins by creating a ScreenDef object. This object is able to determine how many maps have been defined for the active screen, and it has a method to get the screen map object (getScreenMap). Note that as we know that this screen only has one map defined for it, it is retrieved by index. It is also possible to get the active map by name. E.g.
Set objMap = objCurrentDef.getScreenMap(objScr.activeMapName)
The code then loops through all the fields in the map and gets the map field object for each field. It uses the data stored in the map field object to set the HTML INPUT tag's NAME, VALUE, SIZE and MAXLENGTH properties.
The end result is short and simple ASP code that is able to create lengthy and complex HTML pages.